Solved

Need regular expression to test

Posted on 2012-03-12
8
252 Views
Last Modified: 2012-03-16
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.
0
Comment
Question by:cschene
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 37712384
What application, and how is it used in the actual application?
0
 

Author Comment

by:cschene
ID: 37712443
It is actually a home grown internal application......but the app is using boost RegEx
0
 
LVL 12

Assisted Solution

by:Amick
Amick earned 500 total points
ID: 37712464
Application[1-3] myCompany M117 Corp_LA|^_.*

Activate multi-line mode and remember that spacing matters.
0
 
LVL 84

Expert Comment

by:ozo
ID: 37712503
Do you know exactly what parameters are being passed to the boost RegEx function?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 12

Expert Comment

by:Amick
ID: 37712504
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_.*
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 37712545
@Amick

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

Expert Comment

by:Amick
ID: 37712582
@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_.*|^_.*
0
 
LVL 12

Accepted Solution

by:
Amick earned 500 total points
ID: 37715575
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_.*|^_.*
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now