Solved

need a regular expression

Posted on 2004-08-10
9
181 Views
Last Modified: 2010-04-15
before: Test1("Test(" & i & ")", True)
after: Test1("Test(" & i & ")", Test(i), True)
0
Comment
Question by:testn1
9 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11765129
for the word Test or to recognize the pattern of "Test(" & i & ")" to insert the Test(i)
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11765133
i.e.

Test1("foo(" & q & ")", foo(q), True)
0
 

Author Comment

by:testn1
ID: 11765170
correct
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Author Comment

by:testn1
ID: 11765530
an expression that converts the first line into the 2dn:

CheckBox("Test(" & i & ")",True)
CheckBox("Test(" & i & ")",Test(i), True)
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 125 total points
ID: 11766593
The following code:

### C#.NET ###

    static void Main(string[] args)
    {
      string source1 = @"Test1(""Test("" & i & "")"", True)";
      Console.WriteLine("Source 1: " + source1);
      Console.WriteLine("Result 1: " + DoReplace(source1));

      string source2 = @"CheckBox(""Test("" & i & "")"",True)";
      Console.WriteLine("Source 2: " + source2);
      Console.WriteLine("Result 2: " + DoReplace(source2));

      Console.ReadLine();
    }

    static string DoReplace(string inputString)
    {
      const string regexString = @"""Test\(""\s*&\s*(?<var>\w*)\s*&\s*""\)"",";

      System.Text.RegularExpressions.Regex regex;
      regex = new System.Text.RegularExpressions.Regex(regexString);

      return regex.Replace(inputString, new System.Text.RegularExpressions.MatchEvaluator(EvaluateMatch));
    }

    static string EvaluateMatch(System.Text.RegularExpressions.Match match)
    {
      return match.Value + "Test(" + match.Result("${var}") + "),";
    }

###

Produces this output:

### Output ###

Source 1: Test1("Test(" & i & ")", True)
Result 1: Test1("Test(" & i & ")",Test(i), True)
Source 2: CheckBox("Test(" & i & ")",True)
Result 2: CheckBox("Test(" & i & ")",Test(i),True)

###

So just call DoReplace(ORIGINAL_CODE) and the returned string will be the new code.
0
 

Author Comment

by:testn1
ID: 11768485
sorry, maybe i didn't explain myself... I'm doing this inside VS .net... find, replace using regexps...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11783713
You don't need regular expressions to do this simple kind of Find and Replace:

Just put the first one in the Find block, and the second one in the Replace block, and go...

Bob
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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