in reply to Need a cool RegExpresseion. plz help

my $winner = $1 if $R =~ /(\[[^#]*(?:\]|#[^#]*\]))/;

As an explanation, that matches a literal left square bracket followed by anything that is not an octothorp, followed by either a right bracket or anything that is not an octothorpe then a right bracket. If you can have two "winning" groups on one line, you should use minimal rather than greedy matching.

Another way is:

my $winner = $1 if $R =~ /(\[[^#]*(?:#[^#]*)?\])/;

Which means a literal left bracket followed by anything that is not an octothorpe followed by an optional octothorp and anything that is not an octothorp followed by a right bracket. I think I prefer this method. Here is a nicely commented version:

/( # Start capturing. \[ # A literal left bracket. [^#]* # Anthing that is not an octothorp (?: # Group without capturing \# # A literal octothorp [^#]* # Anything that is not an octothorp )? # End group. Group is optional. \] # literal right bracket. )/x

-sauoq
"My two cents aren't worth a dime.";