Solved

need a regular expression

Posted on 2004-08-10
9
179 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

912 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

25 Experts available now in Live!

Get 1:1 Help Now