Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

need help with regular expression in c#

Posted on 2011-09-28
9
Medium Priority
?
313 Views
Last Modified: 2012-08-13
i need some help coming up with a regular expression that represent the following code:

using (new SimpleSDOLogScope(
                      MediatorAgent.Common,
                      null, null, null,
                      typeof(BenefitGroup),
                      null, null, null,

"MediatorAgent.Common" and " typeof(BenefitGroup)" can be any set of legal characters (\w).  but the rest are string literals with spaces in between (number of spaces can vary).  thanks.
0
Comment
Question by:mmingfeilam
  • 6
  • 2
9 Comments
 
LVL 8

Accepted Solution

by:
crysallus earned 668 total points
ID: 36716069
Try this:

using\s+\(new\s+SimpleSDOLogScope\(\s*[\w.()]+\s*,\s*null\s*,\s*null\s*,\s*null\s*,\s*[\w.()]+\s*,\s*null\s*,\s*null\s*,\s*null\s*,

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36716597
Something like this, then?
string pattern = @"using\s*\(new\s+SimpleSDOLogScope\s*\(\s*MediatorAgent\s*\.\s*Common\s*,\s*(?:@""[^""]*""\s*,\s*){3}typeof\s*\(\s*BenefitGroup\s*\s*\)\s*,\s*(?:@?""[^""]*""\s*,\s*){3}";

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1332 total points
ID: 36716603
P.S.

I forgot to ask:  is your pattern intended to be used in code, or in the Find/Replace dialog of Visual Studio?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36716681
If this for Find/Replace, try:

using:Wh*\(new:Wh+SimpleSDOLogScope:Wh*\(:Wh*MediatorAgent\.Common:Wh*,:Wh*(\@*"[^"]*":Wh*,:Wh*)^3typeof\(BenefitGroup\):Wh*,:Wh*(\@*"[^"]*":Wh*,:Wh*)^3

Open in new window

0
 

Author Comment

by:mmingfeilam
ID: 36718820
it's intended for use in the find/replace dialog box in vs 2008.  

crysallus: you solution didn't return anything.
kaufmed: you first solution contains syntax error, and your second solution didn't return anything.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36719230
you first solution contains syntax error, and your second solution didn't return anything.
Second solution was intended for Find/Replace. Not surprising it didn't work in code  = )

For the first, where is the syntax error? It worked fine for me.


string pattern = @"using\s*\(new\s+SimpleSDOLogScope\s*\(\s*MediatorAgent\s*\.\s*Common\s*,\s*(?:@""[^""]*""\s*,\s*){3}typeof\s*\(\s*BenefitGroup\s*\s*\)\s*,\s*(?:@?""[^""]*""\s*,\s*){3}";
string data = @"using (new SimpleSDOLogScope(
          MediatorAgent.Common,
          ""hello"", ""world"", ""hello world"",
          typeof(BenefitGroup),
          ""hello"", ""world"", ""hello world"",";

Console.WriteLine(System.Text.RegularExpressions.Regex.IsMatch(data, pattern));
Console.ReadKey();

Open in new window

0
 

Author Comment

by:mmingfeilam
ID: 36719538
what i means is that when i used the first expression in the find/replace dialog, i got a syntax error, as is expected.  but when i used your second expression, i didn't get anything back.  so can you test the second expression out using the VS2008 find/replace dialog?  also, is there any add-in out there that allows you to do find/replace using .net regular expressions?
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1332 total points
ID: 36719751
I can't do screencasts from work, so I can only offer screenshots, but this was my test:

BeforeAfter
Make sure you have the "Use->Regular Expressions" option enabled.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36779691
And here is the beloved screencast  = )
kaufmed-505623.flv
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

571 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