in reply to Regex matching on anywhere but the beginning or end of a line

You can use positive zero-width assertions:
my $t = q["string (12" or 1 foot or 1') into 6" MySQL varchar"]; $t =~ s/(?<=.)"(?=.)/""/g; print "$t\n";
This means literally 'A double-quote that is preceded by a any char and followed by any char'. See perldoc perlre for the details.

•Update: corrected terminology
•Update: if the string can contain newlines, don't forget to add the /s modifier to the substitution

Replies are listed 'Best First'.
Re: Re: Regex matching - Thanks on anywhere but the beginning or end of a line
by Anonymous Monk on Feb 24, 2003 at 16:37 UTC
    Thank you all for your replies. I spent a couple of hours fighting with this and have the perlre man page pretty much memorized. The answer was in searching for what is rather than looking for two instances of what is not. The best part is I found this site!