This isn't too hard to fix:
You can (not) also use the simpler:my( $quote, $quoted, $end )= $string =~ /(['"])((?:\\.|[^'"\\]+|(?!\1)['"])*)(\1?)/; die "Unclosed quote: $quote$quoted\n" if $quote && ! $end;
but I suspect that [^\1] didn't work in some slightly older versions of Perl (especially since the original regular expression goes out of its way to avoid it)./(['"])((?:\\.|[^\1\\]+)*)(\1?)/
If you have a string that contains a huge sequence of backquoted characters, then you might have to add a + to that part of the regex as well:
(rather, use this corrected one/(['"])((?:(?:\\.)+|[^\1\\]+)*)(\1?)/
). Though that still breaks on/(['"])((?:(?:\\.)+|[^'"\\]+|(?!\1)['"])*)(\1?)/
which would force you to do something more like (updated):"'" . '\vv'x35_000 . "z'"
(:my( $quote, $quoted ); if( $str =~ /(['"])/g ) { my $beg= pos($str); $quote= $1; if( $str !~ /(?<!\\)((?:\\\\)*)\Q$quote/g ) { die "Unclosed quote: ", substr($str,$beg), $/; } my $end= pos($str); $quoted= substr( $str, $beg, $end-$beg-1 ); }
Update: Thanks, merlyn. I knew that had failed in my previous testing but had also run into people thinking it should work enough times that when it "worked" in my test case that didn't test that part of it at all, I jumped to the wrong conclusion.
- tyeIn reply to Re: Text::ParseWords regex doesn't work when text is too long? (fixes)
by tye
in thread Text::ParseWords regex doesn't work when text is too long?
by edan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |