I have following entry in some script
# Find LOGIN tag.
if ((($ln =~ ?<[ ]*LOGIN[ ]?) ||
($ln =~ ?<[ ]*LOGIN$?)) &&
($pword) && ($uname)) {
...
}
It is working, but how? I'm sure match should start with 'm' letter if delimiter is not '/', but this '?' clearly is not delimiter. It is not assertion as well because assertion starts with '?<='. Looks like '<' is just part of pattern searching for '<LOGIN' (with optional white characters). '?' is special character and perl should give me some syntax error like:
C:\>perl -e "/?/"
Quantifier follows nothing in regex; marked by <-- HERE in m/? <-- HER
+E / at -e line 1.
and yet it just works. Deparse does not give any clue:
# perl -MO=Deparse -e '$ln=" < LOGIN > "; $ln =~ ?<[ ]*LOGIN[ ]?'
$ln = ' < LOGIN > ';
$ln =~ ?<[ ]*LOGIN[ ]?;
-e syntax OK
neither does Regex::Explain:
C:\>perl -e "use YAPE::Regex::Explain; $REx = '?<[ ]*LOGIN[ ]?'; print
+ $exp = YAPE::Regex::Explain->new($REx)->explain"
The regular expression:
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
C:\>perl -e "use YAPE::Regex::Explain; $REx = qr/?<[ ]*LOGIN[ ]?/; pri
+nt $exp = YAPE::Regex::Explain->new($REx)->explain"
Quantifier follows nothing in regex; marked by <-- HERE in m/? <-- HER
+E <[ ]*LOGIN[ ]?/ at -e line 1.
Perl version is 5.8.8 on Linux and 5.14.2 on Windows.