[ale] Foolish Perl Question

Ben Coleman oloryn at benshome.net
Fri Mar 22 15:21:01 EST 2002


On Fri, 22 Mar 2002 15:06:19 -0500, Bob Kruger wrote:

>$line[7]=~s/\[font*]//g;

You're close.  Try

$line[7] =~ s/\[font.*?]//g

Note the use of the non-greedy match (the *?, instead of just *).  If
you don't do this, it will match everything from the first font tag in
the line up to the last ] in the line, whether or not it's part of the
font tag.

The other, typical alternative is

s/\[font[^\]]*]//g

the [\]] matches any character that is *not* a ], so the regex won't
end up matching beyond the font tag.

Ben
-- 
Ben Coleman oloryn at benshome.net      | The attempt to legislatively
http://oloryn.home.mindspring.com/   | micromanage equality results, at
Amateur Radio NJ8J                   | best, in equal misery for all.



---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list