Solved

Need regular expression to test

Posted on 2012-03-12
8
265 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:Christopher Schene
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:Christopher Schene
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 84

Expert Comment

by:ozo
ID: 37712503
Do you know exactly what parameters are being passed to the boost RegEx function?
0
 
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 75

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

791 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