473,382 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 27505
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,509 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,509 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

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

Similar topics

2
by: Colin Hale | last post by:
This is driving me bananas. Can't find any info on this anywhere.... SQL 2000 seems to replace double space with a single space when I set a varchar field to " " (2spaces), it only stores " "...
4
by: ucfcpegirl06 | last post by:
Hi, I need help getting rid of trailing white spaces. I am searching a file for various data (not important) and retrieving it. I output the data if found to a file. An example would be:...
5
by: Jonathan Ng | last post by:
Hi, I was wondering if there was a way to include the white spaces in a string. Currently, I am using: scanf("%s", &input); However, this doesn't include the 'space' character or any other...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
3
by: VK | last post by:
If it was already answered somewhere, I'll be glad to be pointed to (after the necessary comments on my search abilities :-) I need as booletproof as possible way to strip out whitespaces from...
8
by: Joe Cool | last post by:
I need to map several columns of data from one database to another where the data contains multiple spaces (once occurance of a variable number or spaces) that I need to replace with a single...
5
by: polturgiest | last post by:
hie all i got a form <form name="TEST" method=POST action="test.php"> <input type="text" name="MyInput"> <input type="submit" name="ACTION" value="SAVE">
0
by: machhalemukesh | last post by:
I am new to regular Expressions. I have two different regex to match email & phone no. I want to match following & split it accordingly. "Email: m_machhale@gmail.com" "Phone No: 45786547546"I have...
2
ashitpro
by: ashitpro | last post by:
I am parsing one xml, I want to replace an attribute with empty string. every node has an attribute, something like this: id="1hyx36uhpi780iq8oiu355" I am using following regex pattern, but...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.