http://www.perlmonks.org?node_id=950857


in reply to Re^2: How do I extract named variable names from regex string
in thread How do I extract named variable names from regex string

Thank you for playing, but you fail.

"" =~ /(?:(?<mon>\w+)\s(?<mon>\w+))?/; say scalar keys %-; # 1
All that's required is for the pattern to match. Taking the pattern, and wrapping it inside a (?: )? will make it match against "" (except for some degenerate cases). If you look back at my code, this is exactly what I did.

Replies are listed 'Best First'.
Re^4: How do I extract named variable names from regex string
by LanX (Saint) on Jan 31, 2012 at 03:47 UTC
    Ups ... you're right!

    Cheers Rolf