Welcome to the Monastery | |
PerlMonks |
Re^3: bracket processingby kcott (Archbishop) |
on Apr 01, 2020 at 00:37 UTC ( [id://11114870]=note: print w/replies, xml ) | Need Help?? |
"As a general practice, I find it's much safer to interpolate strings ... into regexes using \Q \E ..." As a general rule, for regexes in general, that's fine and I'd generally do the same; however, bracketed classes are different. Take a look at "perlrecharclass: Special Characters Inside a Bracketed Character Class". I'll leave you to acquaint yourself with the full text. Here's some pertinent extracts (my emphasis added): Most characters that are meta characters in regular expressions ... lose their special meaning and can be used inside a character class without the need to escape them. So, none of the characters in $delim required escaping. Furthermore, I generally aim to thoroughly test my solutions before posting them. In this instance, I had added a temporary print statement:
which output:
That's exactly the regex I wanted. — Ken
In Section
Seekers of Perl Wisdom
|
|