Solved

need help with regular expression in c#

Posted on 2011-09-28
9
305 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

730 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