A technique I often use for this sort of problem is to have the regex work its way over the problematic section one character at a time and use look around assertions to handle the quoting. Consider:
use warnings; use strict; my $line = qq{Test #1 'Show me Waynes world','Jennys Basketball shoes' +\n}; print "< $line"; $line =~ s/(['"]).+?(['"])/$1SSS$2/g; print "> $line"; $line = qq{Test #2 'Show me Wayne\\'s world','Jenny\\'s Basketball sho +es'\n}; print "< $line"; $line =~ s/(['"]) (?: (?! (?<!\\)\1 ) .)+ \1/$1SSS$1/gx; print "> $line";
Prints:
< Test #1 'Show me Waynes world','Jennys Basketball shoes' > Test #1 'SSS','SSS' < Test #2 'Show me Wayne\'s world','Jenny\'s Basketball shoes' > Test #2 'SSS','SSS'
Note that I removed to redundant sprintfs, showed before and after versions of the test strings, and fixed the quote issue in the second test string.
In reply to Re: skip over an escaped single quote
by GrandFather
in thread skip over an escaped single quote
by bplegend
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |