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?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.