Solved

regular expression help

Posted on 2004-08-10
7
185 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
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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

757 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