in reply to Re: regexp - replace spaces in quoted string
in thread regexp - replace spaces in quoted string
The regex to match quoted strings is discussed in detail in Jeffrey Friedl's excellent book: Mastering Regular Expressions. The regex to do this (and many more) is also available in the superb Regexp::Common CPAN module.
Modifying ambrus's solution with Friedl's optimized regex to match a quoted string (which also allows for escaped characters) gives:
s/("[^"\\]*(?:\\.[^"\\]*)*")/($x=$1)=~y: :_:, $x/ge;
|
|---|