Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

regular expression help

Posted on 2004-08-10
7
Medium Priority
?
193 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
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.

 

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

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.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 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