[Israel.pm] Removing meta characters (^[[1m and ^[[0m) from a file

Amit Aronovitch aronovitch at gmail.com
Sun Jun 27 13:47:31 PDT 2010

On Sun, Jun 27, 2010 at 10:52 PM, Oron Peled <oron at actcom.co.il> wrote:

> Hi,
> First a short answer to Guy -- 'col -b' won't help because it removes the
> meta sequences of backspaces (that's what the 'b' stands for) used in
> Unix/Linux manuals (cat pages FWIW). These sequences were used as a
> neutral format that is later translated to terminal specific escape
> sequences by programs such as more/less etc.
> On Sunday, 27 בJune 2010 12:08:09 Erez David wrote:
> > s/\e[\[01]m//g  does't do the job. since the first [ is not a real
> character
> > it is a meta character...
> Not exactly. The sequences presented are part of ANSI standard of escape
> sequences used to highlight text (bold/underline/etc) on terminals.
> So we don't talk about a special character, but a special *strings*.
> All these sequences have a common form. The simplest format is:
>  <ESCAPE>[<numeric_code>m
> The ASCII code of ESC (decimal 27 as mentioned by someone else here) is
> commonly written as ^[ (control+left bracket) because this is actually
> the ASCII number of this character.
> BTW: if the escape key in your keyboard is broken, you can use control+left
>     bracket as a substitute because it is really the same character.
> The result of this is that when writing the sequence as text, it is often
> presented as: ^[[2m
> But note that the first bracket is part of "control+bracket" which simply
> means the escape character, and the second bracket is the real '['
> character which is part of the sequence (the length of the example above
> is exactly 4 characters)
> Now you should see the problem with your regex -- the '[' in a regex means
> open a character class.... so it is special character for regex.

A correct regex should be:
>    s/\e\[\d+m//
> But this also has an error because it's greedy. Let's fix it:
>    s/\e\[\d+?m//
> Well,  he said

And I thought he actually ment

which is just a minor typo and should actually capture the examples given by
the original poster.

(Well, I'm no expert shlomifologist---it just seemed a more probable
explanation...)  :-)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20100627/542175fe/attachment.htm 

More information about the Perl mailing list