# Doesn't handle embedded like-quotes
my $re_simpleQuoted = qr[
( ["'] )
(
(??{ "[^\1]+?" })
)
\1
]x;
In order to handle embedded quotes you need to go a stage further. The code below seems to handle most cases I have tried of either or both embedded quotes like this "...""..." or '...''....''....', which IMO is the rational way to do it outside of perl source code, and also done this way, "...\"..." and '...\'...'.
It doesn't handle basket cases where an escaped quote is immediately preceded by an escaped escape. Eg. "...\\\"...\"...". This could be addressed, but I think sufficiently rare that I wouldn't bother unless I had specific knowledge that it would arise. There are probably others that it would fail on too.
Code
Output
The PITA of using capturing parens to establish which quote to look for is that it limits the use when combining regexes together as you never know which $n var you captured into.
The 5.8 addition of the $^N variable has made this easier and the use of the experimental features more useful.
The logical extension (IMO) to this would be to extend the non-capturing group syntax to allow capturing to a user defined variable (our vars make sense I think).
Something like
(?: ... :$captured)
The other extension that I would like to see is a way of specifying a variable length match-anything-except-this construct. Like [^"] but longer
(?>>stop when you encounter this)*
Essentially, a non-zero length positive look ahead assertion! :)
Makes sense to me, but then I have no idea of the costs/difficulties these would impose on the regex engine. T'would be nice though.
Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.
|