replace spaces

M

mud_saisem

Hi There,

Could somebody please let me know what the regular expression should
look like if I wanted the only replace the spaces of words between "
".

Example:
string: 1,2,3,4 "5 6 7 8" 9,10,11 "12 13" 14,15,16
result: 1,2,3,4 5_6_7_8 9,10,11 12_13 14,15,16
 
S

sln

Hi There,

Could somebody please let me know what the regular expression should
look like if I wanted the only replace the spaces of words between "
".

Example:
string: 1,2,3,4 "5 6 7 8" 9,10,11 "12 13" 14,15,16
result: 1,2,3,4 5_6_7_8 9,10,11 12_13 14,15,16

s/"(.*?)"/$1/g

If you have something else in mind for $1
do it somewhere else s//&subcall/ge

-sln
 
M

mud_saisem

Well - he asked for replacing spaces with underscores, so:

=====
my $str = q|1,2,3,4 "5 6 7 8" 9,10,11 "12 13" 14,15,16|;

sub unspace {
     my $x = shift;
     $x =~ tr/ /_/;
     return $x;}

$str =~ s/"(.*?)"/unspace "$1"/ge;

print $str, "\n";

I like your work !, I will make very good use of the example that you
have supplied. Thanks for all the effort.

I was trying the following which seemed to be on the right track but
not quite there.

's/"[^*"]*"/_/g'

which was resulting in 1,2,3,4 _ 9,10,11 _ 14,15,16

I just could not figure out how to replace the /_/g with /$1/g but
with the spaces replaced with underscores. If that makes any sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top