jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
So I need todo something with this string that would result into:$values = "'abc', 'dec'f', ''ghc''" ; $sql = "INSERT INTO SOME_TABLE ($columns) VALUES($values) ;
Normally I would be happy if someone gave me the answer, but this time I would really like to understand the regular expression!'abc' 'dec\'f' '\'ghc\''
Next step is to combine:$insert =~ s/(?<!^)'/\\'/g ; # gives: 'abc\' \'dec\'f\' \'... # and I tried: $insert =~ /s(?<!\s)'/\\'/g ; # gives \'abc\' 'dec\'f\'...
At this point I could really use some help on combining the 2 ?$insert =~ s/(?<!\s)'|(?<!^)'/\\'/g ; # wrong result :( $insert =~ s/(?<![^\s]/\\'/g ; # nope again
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: string manipulations with regular expressions
by davorg (Chancellor) on Oct 17, 2006 at 08:33 UTC | |
|
Re: string manipulations with regular expressions
by monarch (Priest) on Oct 17, 2006 at 08:22 UTC | |
|
Re: string manipulations with regular expressions
by johngg (Canon) on Oct 17, 2006 at 09:46 UTC | |
|
Re: string manipulations with regular expressions
by jeanluca (Deacon) on Oct 17, 2006 at 09:03 UTC | |
by wfsp (Abbot) on Oct 17, 2006 at 10:10 UTC | |
by monarch (Priest) on Oct 17, 2006 at 10:20 UTC |