Results 1 to 9 of 9
  1. #1

    Variables in Regular Expression Pattern


    I am trying to set a Pattern that includes a value that changes frequently.

    The pattern is: Operate::Variable1,Variable2,Close:Empty

    Variable1 and Variable 2 change in values every time. However the rest is constant.

    I tried: "Operate::"&Variable1&","&Variable2&am p;",Close:Empty"
    but that did not work.

    Please help

  2. #2

    Re: Variables in Regular Expression Pattern

    What exactly do you want a pattern or a specific string?

    As such r.e. would be


  3. #3

    Re: Variables in Regular Expression Pattern

    Thank you for responding. I want a pattern that can be re-used over and over to find this text in the same file.

    If my Variable1= Test and Variable2= Quiz
    Then it should find "Operate:Test,Quiz,Close:Empty" only

    The next time if Variable1= Book and Variable2= Paper
    then it should find "Operate:Book,Paper,Close:Empty" only

  4. #4

    Re: Variables in Regular Expression Pattern

    Then your pattern is correct. How did you use it?

    As such your pattern is not a pattern it is just the string you are expecting to see.

  5. #5

    Re: Variables in Regular Expression Pattern

    This is my code. if strPattern="Operate::"&Variable1&","&V ariable2&",Close:Empty"
    Nothing is found!

    Public Function arrGetPatternTextFromFile (strPattern,strFilePath)

    Const ForReading = 1
    Dim i
    Dim objRegEx, strSearchString, colMatches, strMatch
    Dim arrMatches()


    Set objRegEx = CreateObject("VBScript.RegExp")
    objRegEx.Pattern =strPattern
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strFilePath, ForReading)

    Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)
    If colMatches.Count > 0 Then

    For Each strMatch in colMatches
    ReDim Preserve arrMatches(i)

    End If


    End Function

  6. #6

    Re: Variables in Regular Expression Pattern

    Try adding this

    objRegEx.Global = True
    objRegEx.IgnoreCase = True

  7. #7

    Re: Variables in Regular Expression Pattern

    I will. Thanks. one more favor please. If I wanted to get this code to return the line number the text was found. What do I need to do.

    Also, if I wanted to start the search at a specific line number to the end. what do I do?

    Thank you so much.

  8. #8

    Re: Variables in Regular Expression Pattern

    Well you can. For getting the line # you will have to get match position and then count the # of vbCrLf chars before that. You can use a Mid to cut the string and then use Split to convert the string into an Array and take its UBound.

    For your second issue also you need to a similar way to count vbCrLf and skip the text using positions (again a mid)

  9. #9

    Re: Variables in Regular Expression Pattern

    Adding objRegEx.Global = True
    objRegEx.IgnoreCase = True

    did not work



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 07:52 PM.

Copyright BetaSoft Inc.