Solved

need help with regular expression in c#

Posted on 2011-09-28
9
300 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 167 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 74

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 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 333 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
 
LVL 74

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 74

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 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 333 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 74

Expert Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now