From the documentation, I see
$rex = qr/my.STRING/is;
print $rex; # prints (?si-xm:my.STRING)
But I am not sure how to understand (?si-xm:...)
. If I do a print on qr/quick|lazy/
, I got (?-xism:quick|lazy)
. What does it mean here (?-xism:...)
too?
Thanks!
qr// is documented in perlop in the "Regexp Quote-Like Operators" section. Just like qq"..." aka "..." allows you to construct a string, qr/.../ allows you to construct a regular expression.
The qr// is a regex quoting operator that stores my regex in a scalar (and as a quoting operator, its documentation shows up in perlop). The qr// compiles the pattern so it's ready to use when I interpolate $regex in the match operator.
The Binding Operator, =~ Matching against $_ is merely the default; the binding operator ( =~ ) tells Perl to match the pattern on the right against the string on the left, instead of matching against $_ .
Regular Expression (Regex or Regexp or RE) in Perl is a special text string for describing a search pattern within a given text. Regex in Perl is linked to the host language and is not the same as in PHP, Python, etc. Sometimes it is termed as “Perl 5 Compatible Regular Expressions“.
As explained in the perlre man-page:
Any letters between
?
and:
act as flags modifiers [...]
The letters before the -
are positive modifiers; those after it are negative modifiers. So, for example, (?-xism:quick|lazy)
means that whitespace and comments are not allowed inside the parentheses, the parenthesized part is not case-sensitive, a dot .
does not match newlines, and ^
and $
do not match line-start and line-end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With