and got as output:$values = "'abc', 'dec'f', ''ghc''" ; my @quotedvalues = (); while ( $values =~ m/\'(.*?)\'(?:,|\z)/g ) { my $value = $1; $value =~ s/\'/\\\'/g; push( @quotedvalues, $value ); } print( join( "\n", @quotedvalues ) );
abc dec\'f \'ghc\'
Note that your insert statement will have to run as a loop, once for each value that you want to insert. Thus, ultimately, you want an array of values out of the provided string.
Also note that, once you've extracted each value from the outside single quotes surrounding that value, you can use the database function ->quote() from the DBI module instead of running a regular expression like I did in the above example.
In reply to Re: string manipulations with regular expressions
by monarch
in thread string manipulations with regular expressions
by jeanluca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |