469,270 Members | 1,117 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

how to replace multiple white spaces with a single space using regex?

34
Expand|Select|Wrap|Line Numbers
  1. my $tsr = "i am         a                                     good girl";
  2.  
i want output will be,
"i am a good girl"

Any suggestions??????/
Jan 9 '08 #1
5 27075
KevinADC
4,059 Expert 2GB
i.e my $tsr = "i am a good girl";
i want output will be,
"i am a good girl"

Any suggestions??????/
Next time show some effort before posting a question.

Expand|Select|Wrap|Line Numbers
  1. $tsr =~ s/\s+/ /g;
And use the code tags to post code. See the posting guidelines.
Jan 9 '08 #2
cnsabar
40
You can also use this Regex. to produce exact output.

Expand|Select|Wrap|Line Numbers
  1. $tsr =~ s/ {1,}/ /g;
  2.  
Jan 9 '08 #3
numberwhun
3,503 Expert Mod 2GB
You can also use this Regex. to produce exact output.

Expand|Select|Wrap|Line Numbers
  1. $tsr =~ s/ {1,}/ /g;
  2.  
Essentially, that does the same thing as Kevin's regex. It produces the "exact" same output.
Jan 9 '08 #4
cnsabar
40
Yes, it produce exact output.
but, I thought there may be line break in the given string.

Essentially, that does the same thing as Kevin's regex. It produces the "exact" same output.
Jan 9 '08 #5
numberwhun
3,503 Expert Mod 2GB
Yes, it produce exact output.
but, I thought there may be line break in the given string.
doesn't look like it. The text is included in the variable assignment.

Regards,

Jeff
Jan 9 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by ucfcpegirl06 | last post: by
5 posts views Thread by Jonathan Ng | last post: by
11 posts views Thread by gopal srinivasan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.