in reply to Regular Expression Pieces

You need to specify the 'g' option to get all occurences, but sometimes relying on $1, etc. is overkill:
my $a = "this is a test [[1]] [[ a ]] [[ abd ]] [[\%object,key]]"; print $_,$/ for $a =~ /(\[\[[^\]]+\]\])/g; __DATA__ [[1]] [[ a ]] [[ abd ]] [[%object,key]]
UPDATE: Haven't you people read Death to Dot Star!? ;) Seriously, while a non-greedy dot star works does work for this example, i cannot recommend using it when there is a better solution: a negated character class ([^\]]+).

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: Regular Expression Pieces
by Gilimanjaro (Hermit) on May 08, 2003 at 10:20 UTC

    If performance is not an issue, .* is usually a lot more readable...

    Wouldn't it be nice if the regex engine optimizes .*'s followed by a character(class) to a negated character class? Seems true to DWIM to me...