We help IT Professionals succeed at work.

Need regular expression to test

I need a regular expression that will match on the following conditions:
1. Needs to match any string that contains “Application1 myCompany M117 Corp_LA”
2. Needs to match any string that contains “Application2 myCompany M117 Corp_LA”
3. Needs to match any string that contains “Application3 myCompany M117 Corp_LA”
4. Needs to match any string that starts with an underscore. For example _app1 or _app_2, but NOT app_3

I’ve tried:
(Application1 myCompany M117|Application2 myCompany M117 Corp_LA|Application3 myCompany M117 Corp_LA)|^(_.*)

This seems to work in an online regex tester, but doesn’t work in the actual application.
Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
What application, and how is it used in the actual application?
Christopher ScheneSystem Engineer/Software Engineer

Author

Commented:
It is actually a home grown internal application......but the app is using boost RegEx
Commented:
Application[1-3] myCompany M117 Corp_LA|^_.*

Activate multi-line mode and remember that spacing matters.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
Do you know exactly what parameters are being passed to the boost RegEx function?

Commented:
Lacking a multi-line mode you might also try

Application[1-3] myCompany M117 Corp_LA|\n_.*

OR

Application[1-3] myCompany M117 Corp_LA|\r_.*
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
@Amick

You may want to adjust your last offering since it wouldn't account for the first line starting with an underscore  ; )

Commented:
@kaufmed - Excellent point!

I had my eye on those cases where multi-line mode might be necessary and not available, but clearly the unique first-line case can be addressed by appending the original |^_.* as in:

Application[1-3] myCompany M117 Corp_LA|\r_.*|^_.*
Commented:
One more modification:

Boost documentation says:
The escape sequence \R matches any line ending character sequence, specifically it is identical to the expression (?>\x0D\x0A?|[\x0A-\x0C\x85\x{2028}\x{2029}]).

To take advantage of that use:

Application[1-3] myCompany M117 Corp_LA|\R_.*|^_.*

Explore More ContentExplore courses, solutions, and other research materials related to this topic.