Parsing question

How can I best search for this data in a larger string, where the number of spaces in between each word can vary?   regex?  


MOTHER             RACE       GENDER    AGE (DOB)      SSN      PHONE
LVL 1
HLRosenbergerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
That's what I would use.  I would also use word boundaries to make sure it doesn't match in the middle of a word - ex: TRACE
myRegExp.Pattern = "\s*\b(MOTHER|RACE|GENDER|AGE|\(DOB\)|SSN|PHONE)\b\s*"

Open in new window

HLRosenbergerAuthor Commented:
OK,  thanks.  I know regular expressions stuff is powerful, but I have not used them much.   In your example of TRACE, I would not want that to match because, even thought it contains RACE.   There would only ever be spaces between MOTHER and RACE, so I would want "MOTHER     TRACE" to not match.
hieloCommented:
>>  In your example of TRACE, I would not want that to match because, even thought it contains RACE
That's exactly why I included the "\b" (word boundary) delimiters.  The expression above would match RACE, but not if it is part of a larger word.

Are you looking for the entire substring "MOTHER             RACE       GENDER    AGE (DOB)      SSN      PHONE" in that specific order in a larger string (with varying spaces between the words of course), OR are you looking for any of those words?  The regex I posted looks for each of those words -- the "|" means "OR".  In other words it states, match "MOTHER OR RACE OR ..."
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

HLRosenbergerAuthor Commented:
Also, I need the index/offset of that substring within a larger string
HLRosenbergerAuthor Commented:
Ah, sorry.  I'm looking for a string with ALL those words, with varying spaces between the words.
hieloCommented:
OK, then change the "|" to "\s+"
myRegExp.Pattern = "\s*\b(MOTHER\s+RACE\s+GENDER\s+AGE\s+\(DOB\)\s+SSN\s+PHONE)\b\s*"

Open in new window

HLRosenbergerAuthor Commented:
ah, great!  that works.  So in english, what does this search string do?  

search for a string that begins and ends with spaces, and

Inside the parens is the string to search for, and

\s+ means there can be any number of spaces .

What does the \b mean?
hieloCommented:
>> \s+ means there can be any number of spaces .
\s is not limited to a single space character (as in spacebar).  It also takes into account \t, \r, \f, \n.  If you want just "spacebar" characters, you will need to change \s to spacebar (literally).  The "+" means one or more.  Meaning that there must be at least one space in between the words.

The \b stands for "Word Boundary", which prevents matching in the "middle" of a larger string.  For instance, if your input string had:
"MOTHER             RACE       GENDER    AGE (DOB)      SSN      PHONES" but you only want PHONE (singular), then the \b would prevent PHONES from matching.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
Thanks so much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.