in reply to What regex can match arbitrary-length quoted string?
It seems the \\., which captures the \" in the target, is not possessive, and is causing the error.
The following works in the given case. Are there cases where it fails?
print "NOT MATCHED!\n" unless /^ " (?: [^"\\]++ | (?: \\. )++ )*+ " /x ;
Update:
Playing around more, it seems that the possessives are not needed on the internals, but only that the \\. should have a quantifier:
This works on a string of length 100 million, in <2s on my machine. (I didn't try any longer strings.)print "NOT MATCHED!\n" unless /^ " (?: [^"\\]+ | (?: \\. )+ )*+ " /x ;
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: What regex can match arbitrary-length quoted string?
by QM (Parson) on Sep 29, 2017 at 13:26 UTC | |
Re^2: What regex can match arbitrary-length quoted string?
by Anonymous Monk on Sep 29, 2017 at 13:51 UTC | |
by QM (Parson) on Oct 03, 2017 at 10:46 UTC | |
by jimav (Sexton) on Aug 26, 2023 at 00:29 UTC |
In Section
Seekers of Perl Wisdom