Solved

regular expression space separator

Posted on 2011-02-24
22
561 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exchange 2010 Transport Rule Regex 28 93
What's wrong with this web.config regex? 3 41
To remove white-space and leading zeros from string 12 44
Two RegEx conditions in one 3 42
by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
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…

947 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

18 Experts available now in Live!

Get 1:1 Help Now