Solved

need a regular expression

Posted on 2004-08-10
9
178 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

17 Experts available now in Live!

Get 1:1 Help Now