banduwgs has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
I am checking list of email subjects for a certain values. I want to ignore all RE, FW at the begining. I used following code:
$match_count += 1 if ($subject =~ /^[RE:\s*|FW:\s*]*$match_string\i*$/ +);
When I passed $match_string = "Are you a Perfect Sinhalese????" it gives following error:
Nested quantifiers in regex; marked by <-- HERE in m/^[RE:\s*|FW:\s*]* +Are you a Perfect Sinhalese??? <-- HERE ?\s*$/ at C:/Perl/lib/LTG/DocBuddy/Relation.pm line 496.
Code at line 496 is given above. But it works fine with $match_string = "Are you a Perfect Sinhalese". What's the problem here? And how I can avoid it?
Thanks - SB

update (broquaint): s{<(/)?pre>}(<${1}code>)g

Replies are listed 'Best First'.
Re: Error! Nested quantifiers in regex
by Abigail-II (Bishop) on Sep 16, 2003 at 09:06 UTC
    ? is special for the regexp machine. What you want is:
    /^(?:RE:\s*|FW:\s*)*\Q$match_string\E$/

    The \Q ... \E tells the regexp engine that anything in between should be taken "as is". I also removed the \i*. I do not know what you think \i is, but any string will end with zero or more of them. Finally, one uses ( ) or (?: ) for grouping, [RE:\s*|FW:\s*]* means something else. That would match any string consisting of whitespace, the capital letters E, F, R, W and the characters : and |.

    Abigail

      Thank you, that's right. It works. Oh, "i" is a mistake, I don't have it in my code - SB
Re: Error! Nested quantifiers in regex
by leriksen (Curate) on Sep 16, 2003 at 09:12 UTC
    a ? means that the preceding character or group is optional - a ? is called a qualifier - so Sinhalese? mean that Sinhales and Sinhalese will match.
    however ???? means that the ? quantifiers are applying to each other - nested in other words, and that is not allowed in Perl's regex implementation