Matching VbCrLf with RegEx

Hello Experts,

I could use some help with Regular Expressions. My problem is easy to explain:

Normally the pattern I am trying to match looks like this:

CASUALTY/INITIAL-17051/STBD FIN STAB OVERHEATS/EIC:TR00000/CAT:2//

The match syntax looks like this:
(CASUALTY.*\/.*)\/\/
Which returns:
CASUALTY/INITIAL-17051/STBD FIN STAB OVERHEATS/EIC:TR00000/CAT:2

The problem is that sometimes the message comes in with a VbCrLf somewhere in the string and it returns a null.

I tried to but \r\n in various places but nothing seems to work. Any assistance with this would be greatly appreciated!
John Clarklogistics specialistsAsked:
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.

Fabrice LambertFabrice LambertCommented:
Hi,

Maybe look for any character or CRLF (enclosed in non capturing group) instead ?
(CASUALTY(?:.|[\r\n])*\/(?:.|[\r\n])*)\/\/

Open in new window

0

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
John Clarklogistics specialistsAuthor Commented:
Works like a charm! I tested thoroughly with a hard return in various places and they ALL return exactly what I was looking for. A thousand thanks, a thousand times over...

Would it be too much to ask to explain what those additional characters mean?
0
Fabrice LambertFabrice LambertCommented:
My best advice will be to look at an online regex tester site, such as https://regexr.com/
Everything is explained there (and much better than I will ever do).
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

John Clarklogistics specialistsAuthor Commented:
Will do and thanks again!
0
John Clarklogistics specialistsAuthor Commented:
Opps...I spoke too soon. It is grabbing everything after the escaped "//" (\/\/). I want the pattern match to stop after it finds it...
0
Fabrice LambertFabrice LambertCommented:
Guess in its actual form, the regex isn't precise enough.

You'll need to provide more details about the message's structure, so we can write a more accurate regex.
0
John Clarklogistics specialistsAuthor Commented:
Sure thing, and thanks for sticking with this.

The complete message can look like this:

FM SOMBODY
TO SOMEBODY ELSE
REF/A/SOME OBSCURE BOOK//
MSGID/CASREP/DDG 123/123//
CASUALTY/INITIAL-17051/STBD FIN STAB OVERHEATS/EIC:TR00000/CAT:2//
1. THE PROBLEM IS THIS
//
THE END

The pattern you provided grabs returns:
CASUALTY/INITIAL-17051/STBD FIN STAB OVERHEATS/EIC:TR00000/CAT:2//
1. THE PROBLEM IS THIS
//
THE END

What I want is:
CASUALTY/INITIAL-17051/STBD FIN STAB OVERHEATS/EIC:TR00000/CAT:2

Hope this clears it up and thanks again...
0
Fabrice LambertFabrice LambertCommented:
After a quick analysis in the part you want to extract, it looks like you have:

the word CASUALTY (is that always the case ?)
followed by a slash
followed by the word INITIAL (is that always the case ?)
followed by a minus
followed by 5 numbers
followed by a slash
followed by a description (anything that isn't a slash ?)
followed by a slash
followed by 3 letters (always EIC ?)
followed by a semi-colon
followed by 2 letters (always TR ?)
followed by 5 numbers
followed by a slash
followed by 3 letters (always CAT ?)
followed by a semi-colon
followed by a number
followed by 2 slash

There are some parts wich I'm still unsure about, please let me know if I'm right, or provide a correction.
0
John Clarklogistics specialistsAuthor Commented:
Not quite that complicated. There are really two constants here: the string "CASUALTY/" and the next "//" it encounters. I am looking for everything between (including any VbCrLf which was causing the problem) them. More specifically, I want a string that starts with "CASUALTY/" and all the elements before, but not including the "//".

For the record,I use the resulting string as a slash ("/") delimited array for populating an Access table.
0
Fabrice LambertFabrice LambertCommented:
This should do the job then:
(CASUALTY\/(?:.|[\r\n])*?)\/\/

Open in new window

1
John Clarklogistics specialistsAuthor Commented:
I will try it first thing tomorrow morning at work. Really appreciate your help with this.
0
John Clarklogistics specialistsAuthor Commented:
Most excellent! Gracie mille. I tried to mark the last contribution as the actual "solved" post but was unable too.

Got some reading to do now so I can figure out why yours works.

Thanks again.
0
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
Regular Expressions

From novice to tech pro — start learning today.