in reply to regexp - replace spaces in quoted string

Try
s/(".*?")/($x=$1)=~y: :_:, $x/ge

Replies are listed 'Best First'.
Re^2: regexp - replace spaces in quoted string
by eyepopslikeamosquito (Archbishop) on Sep 06, 2005 at 10:43 UTC

    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;