in reply to Re: qr delimiter question
in thread qr delimiter question
You can see how perl is parsing the regex by printing it:
As you see, a single backslash is interpreted as escaping the parens from the qr(), rather than as part of the regex. A double-backslash escapes the backslash in the regex, so there's no backslashy way to match a literal paren. You have to use a character class, plus a backslash, unless you're going to have a balancing paren in the expression, in which case, perl will notice the balanced parens and Do The Right Thing.>perl -e "print qr(a(b)c)" (?-xism:a(b)c) >perl -e "print qr(a\(b\)c)" (?-xism:a(b)c) >perl -e "print qr(a\\(b\\)c)" (?-xism:a\\(b\\)c)
>perl -e "print qr(a\(bc)" Unmatched ( in regex; marked by <-- HERE in m/a( <-- HERE bc/ at -e li +ne 1. >perl -e "print qr(a[(]bc)" Search pattern not terminated at -e line 1. >perl -e "print qr(a[\(]bc)" (?-xism:a[(]bc)
|
|---|