?
Solved

regular expression space separator

Posted on 2011-02-24
22
Medium Priority
?
591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Suggested Courses

770 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