Solved

need help with regular expression in c#

Posted on 2011-09-28
9
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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 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
Industry Leaders: 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 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 75

Expert Comment

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…

705 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