Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

regular expression help

Posted on 2004-08-10
7
Medium Priority
?
194 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
6 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 500 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

879 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