<div dir="ltr">Thanks, but none of the alternative solutions work for me on Ubuntu 14.04 :(<div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 16, 2016 at 5:44 AM, Kjetil Torgrim Homme <span dir="ltr"><<a href="mailto:kjetil.homme@redpill-linpro.com" target="_blank">kjetil.homme@redpill-linpro.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Den 16. aug. 2016 03:28, Kun Zhang skreiv:<br>
> ## Regular Expression<br>
> line 338: path=$(echo "$matches" | perl -pe 's/\e\[?.*?[\@-~]//g')<br>
> Why not use sed or builtin?<br>
> Who wants to install all of perl to run bash code?<br>
><br>
><br>
> I googled around but didn't find other code that successfully remove<br>
> ANSI color codes for me.<br>
> So I landed with the first solution that worked. I can look harder though.<br>
<br>
<br>
</span>rewriting the regexp to not be dependent on Perl's non-greedy syntax is<br>
quite simple. the bash-only solution below is a bit roundabout since<br>
there is no substitute function for regular expressions, so we have to<br>
extract the actual plain strings using the =~ operator and then do text<br>
substitutions:<br>
<br>
path="$matches"<br>
printf -v ansi_color_re '\033\\[[^@-~]*[@-~]'<br>
while [[ "$path" =~ $ansi_color_re ]]<br>
do<br>
path=${path/${BASH_REMATCH[0]}<wbr>/}<br>
done<br>
<br>
(note, I changed the [ after ESC to be mandatory, I think that is more<br>
correct.)<br>
<br>
alternatively, you can write it using GNU sed like this:<br>
<br>
path=$(echo "$matches" | sed 's/\o033\[[^@-~]*[@-~]//g'<br>
<br>
or more portably:<br>
<br>
printf -v ESC '\033'<br>
path=$(echo "$matches" | sed s/${ESC}'\[[^@-~]*[@-~]//g'<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Kjetil T. Homme<br>
Redpill Linpro - Changing the game<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Best wishes<br>Kun Zhang</div></div>
</div></div>