Solved

regular expression space separator

Posted on 2011-02-24
22
556 Views
Last Modified: 2012-05-11
Hello -

What is the regular expression separator that represents a 'white space' or blank space' between two words in a string?

For example, in the string 'PO#1234 History', What could I use as a space separator to detect the blank space between '4' and 'History'

thanks!
0
Comment
Question by:DTwined
  • 13
  • 9
22 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34975952
\s+ matches one or more spaces (or tabs, or newlines)
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34975959
Depending on the regex engine you're working with, it may also be helpful to use \b which matches a word boundary, for example:
\bblah\b
from string:
"in this case blahdeblah won't match, but blah will"
0
 

Author Comment

by:DTwined
ID: 34975960

Are there any other options?
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34975970
You can also use just a space character, or a subset of your choice of characters eg just spaces and tabs, but not newlines: [ \t]+
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34975974
Do you have any examples that you're having trouble with?
0
 

Author Comment

by:DTwined
ID: 34975980

What is an example of a space character?
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34975985
There are space characters between these words. Is that what you mean?
0
 

Author Comment

by:DTwined
ID: 34975987

No, unfortunately it's a crappy UI where  I need to enter in a separator to parse a string. I can't seem to find a separator for white space that will work correctly.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34975996
Can you explain which language or tool you're using?
0
 

Author Comment

by:DTwined
ID: 34975998
Yes Terry. Like this string, 'PO#1234 History'.
I need to separate  'PO#1234' and 'History'.
0
 

Author Comment

by:DTwined
ID: 34976005

It's an internal tool with no documentation, unfortunately.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:Terry Woods
ID: 34976014
Does the tool have its own interface for entering the separator, or is it done via a command line (linux, DOS, etc)?
0
 

Author Comment

by:DTwined
ID: 34976043

It has its own interface for entering the separator.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34976049
Would putting quotes around it help? ie " "
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34976053
Do you know what framework or language the tool was build with?
0
 

Author Comment

by:DTwined
ID: 34976069

I'm betting it's Linux or Unix.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34976073
You could also try:
' '
or
\
(There's a space character after the \ character)
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34976077
Or even:
\\
(There's a space character after the \ characters)
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 34976080
Or (a long shot):
'\ '
or
'\\ '
0
 

Author Comment

by:DTwined
ID: 34976086
So it would be like this (quotes used to show space), '\ ' or '\\ '?
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34976127
I'd try it with and without the quotes
0
 

Author Comment

by:DTwined
ID: 34976137

Definitely. I'll give it a try first thing in the morning. Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now