Solved

regular expression help

Posted on 2004-08-10
7
192 Views
Last Modified: 2010-05-02
need a regular expression that will search reaplce  line1 into lin2


CheckBox("Test(" & i & ")",True)
CheckBox("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
7 Comments
 
LVL 6

Expert Comment

by:PePi
ID: 11765574
question is quite vague. please clarify.
0
 

Author Comment

by:testn1
ID: 11765791
i need to find and replace the structure on line 1 by the structure on line 2 .. Test and True can be any value
0
 
LVL 6

Expert Comment

by:PePi
ID: 11765852
where are you searching for this "structure"??? is it in code? or is it from a file?
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:testn1
ID: 11766019
code
0
 
LVL 2

Expert Comment

by:amg42
ID: 11766652
Dim re As VBScript_RegExp_55.RegExp
Set re = New RegExp

re.IgnoreCase = True
re.Global = True
re.Pattern = "CheckBox\(""([^)]+)\("" & i & ""\)"",([^)]+)\)"

' The 'foobar' and the 'False' below are just an example to show that this will match (and replace) other
' values than 'Test' and 'True', as you indicated.
Call MsgBox(re.Replace("CheckBox(""foobar("" & i & "")"",False)", "CheckBox(""$1("" & i & "")"",$1(i), $2)"))



0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 125 total points
ID: 11767086
   Sub Main()

        Dim source1 As String = "Test1(""Test("" & i & "")"", True)"
        Console.WriteLine("Source 1: " + source1)
        Console.WriteLine("Result 1: " + DoReplace(source1))

        Dim source2 As String = "CheckBox(""Test("" & i & "")"",True)"
        Console.WriteLine("Source 2: " + source2)
        Console.WriteLine("Result 2: " + DoReplace(source2))

        Console.ReadLine()

    End Sub

    Function DoReplace(ByVal inputString As String)

        Const regexString As String = """Test\(""\s*&\s*(?<var>\w*)\s*&\s*""\)"","

        Dim regex As System.Text.RegularExpressions.Regex
        regex = New System.Text.RegularExpressions.Regex(regexString)

        Return regex.Replace(inputString, New System.Text.RegularExpressions.MatchEvaluator(AddressOf EvaluateMatch))

    End Function

    Function EvaluateMatch(ByVal match As System.Text.RegularExpressions.Match) As String

        Return match.Value + "Test(" + match.Result("${var}") + "),"

    End Function
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month6 days, 3 hours left to enroll

627 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