Solved

need a regular expression

Posted on 2004-08-10
9
182 Views
Last Modified: 2010-04-15
before: Test1("Test(" & i & ")", True)
after: Test1("Test(" & i & ")", Test(i), True)
0
Comment
Question by:testn1
[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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why use this lambda? 12 98
Coding for the first time 9 104
Set custom font WPF 2 27
UWP: Create an Image/Bitmap, Draw another image on it an save. 1 49
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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