Solved

regular expression help

Posted on 2004-08-10
7
190 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
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: 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 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