LanX has asked for the wisdom of the Perl Monks concerning the following question:
I read once that JS-regexes follow the standards of Perl4.
Now I was quite surprised to learn that JS doesn't have a /s single-line modifier to let '.' also match on linebreaks like \n.
As a compensation JS offers to use [^] to match everything (the negation of nothing is everything).
>>> "a <\n \n> z".match('<[^]*>') ["<\n \n>"]
I like the concept and was wondering if there is any equivalent in Perl ...
Here [^] is a syntax error because at this position Perl magically expects ']' to be part of the negated char-class and still expects another closing ']'.
The closest that I was able to find was (?:.|\n)
DB<118> "a <\n \n> z" =~ /<(?:.|\n)*>/ ; $ & => "<\n \n>"
Any other suggestions?
Cheers Rolf
Update
Another option is to use single-line locally: (see perlrecharclass)
DB<146> "a <\n \n> z" =~ /<(?s:.)*>/;$ & => "<\n \n>"
not shorter but cleaner!