Solved

need a regular expression

Posted on 2004-08-10
9
180 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Install Problem 13 31
C# Desktop Application 3 35
Get distinct values from excel or comm seperated file 4 25
Problem with SelectList in .NET MVC application 1 17
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.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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