Reputation: 9056
In the following expression:
if (($$_ =~ /^.+:\s*\#\s*abcd\s+XYZ/)
Upvotes: 0
Views: 80
Reputation: 91373
Have a look at this site
Here is the given explanation of your regex:
Token Meaning
^ Matches beginning of input. If the multiline flag is set to true,
also matches immediately after a line break character.
.+ Matches any single character except newline characters.
The + quantifier causes this item to be matched 1 or more times (greedy).
: :
\s* Matches a single white space character.
The * quantifier causes this item to be matched 0 or more times (greedy).
\# #
\s* Matches a single white space character.
The * quantifier causes this item to be matched 0 or more times (greedy).
abcd abcd
\s+ Matches a single white space character.
The + quantifier causes this item to be matched 1 or more times (greedy).
XYZ XYZ
Upvotes: 0
Reputation: 31508
As for pt. 2:
Line beginning with (^
) one or more characters (.+
), colon (:
), zero or more whitespace characters (\s*
), a hash (\#
), zero or more whitespace characters (\s*
), the string "abcd" (abcd
), one or more whitespace characters (\s+
), then the string "XYZ" (XYZ
).
(emphasis added on discrepancies.) Do note that there is no anchor on the end of line ($
), thus this only concerns the beginning.
Upvotes: 1
Reputation: 98388
You have the last "one or more" and "zero or more" reversed from what the regex actually does.
$$_
dereferences the scalar reference in $_
.
Upvotes: 2
Reputation: 2709
Concerning 2., your explanation of the regex is not entirely correct.
/^.+:\s*#\s*abcd\s+XYZ/
means one or more characters (starting at the beginning of the string) followed by a colon, followed by zero or more whitespace characters, followed by one hash character, followed by zero or more whitespace characters, followed by 'abcd', followed by one or more whitespace characters, followed by 'XYZ'.
Upvotes: 1