Couldn't regex.search from text area/property?

  1. 5 days ago

    Aditya N

    Nov 8 Pre-Release Testers, Xojo Pro

    I have the following setup :
    btnSearch Action :

    'Prepare a regular expression object
    Dim myRegEx As RegEx
    Dim myMatch As RegExMatch
    Dim result() As String
    Dim counter As Integer
    Dim temp As Integer = 0 
    Dim tempCount As Integer = 0 
    myRegEx = New RegEx
    myRegEx.Options.TreatTargetAsOneLine = False
    //myRegEx.Options.LineEndType  = 3
    myRegEx.SearchPattern = "^ +Name=(.*)"
    'Pop up all matches one by one
    txtAreaInput.SelStart = 0
    txtAreaInput.SelLength = txtAreaInput.Text.Len
    txtAreaInput.Text = txtAreaInput.SelText
    MsgBox(monodis)
    myMatch = myRegEx.Search(txtAreaInput.Text) //In Here the txtAreaInput.Text is always empty
    //tempCount = myMatch.SubExpressionCount + 1
    //Redim result(tempCount)
    while myMatch isa RegExMatch
      // do something with match
      MsgBox(counter.ToText)
      result.Append(myMatch.SubExpressionString(1))
      counter = counter + 1
      MsgBox(myMatch.SubExpressionString(1))
      myMatch = myRegEx.Search() // Get the next
    wend
    For temp = 0 To result.Ubound
      txtAreaResult.AppendText(result(temp))
    Next temp
    

    btnShell Action :

    Dim s As New Shell
    Dim cmd As String
    cmd = """C:\Program Files (x86)\Mono\bin\monodis.exe"" --assemblyref C:\Users\nameless\Documents\Works\Compiling\Hurricane\Hurricane\bin\Release\Hurricane.exe"
    s.Execute(cmd)
    monodis = s.ReadAll
    txtAreaInput.Text = monodis
    txtAreaInput.Refresh

    The btnShell is producing the following output on my case :

    WARNING: The runtime version supported by this application is unavailable.
    Using default runtime: v4.0.30319
    AssemblyRef Table
    1: Version=2.0.0.0
            Name=mscorlib
            Flags=0x00000000
            Public Key:
    0x00000000: B7 7A 5C 56 19 34 E0 89
    2: Version=2.0.0.0
            Name=System.Windows.Forms
            Flags=0x00000000
            Public Key:
    0x00000000: B7 7A 5C 56 19 34 E0 89
    3: Version=2.0.0.0
            Name=System
            Flags=0x00000000
            Public Key:
    0x00000000: B7 7A 5C 56 19 34 E0 89
    4: Version=2.0.0.0
            Name=System.Drawing
            Flags=0x00000000
            Public Key:
    0x00000000: B0 3F 5F 7F 11 D5 0A 3A

    The problem is when at first i clicked the btnShell then the btnSearch, the txtAreaInput.Text will always empty while processing into the myMatch . But if i pasted manually the btnShell output then the btnSearch will outputting the right regex output.

    I have read the TextArea manual countless time but still haven't figured out on why the assigned value from btnShell is not being processed by the btnSearch.

    The problematic line from the btnSearch is in "myMatch = myRegEx.Search(txtAreaInput.Text)". The strange thing is when outputting into MsgBox, the txtAreaInput.Text value is can be read but when passed into myMatch it just processing it as empty value.

    Hello Aditya, in your code you have lines like this:

    + "Name=mscorlib" + EndOfLine _

    and your search pattern is looking for 1 or more spaces before Name:

    myRegEx.SearchPattern = "^ +Name=(.*)"

    Changing your SearchPattern to "^Name=(.*)" then your sample code works.
    You could add a blank space (or more) before Name too without changing your SearchPattern.

    Edit: are you sure there are spaces before Name and not a tab or two?

    1: Version=2.0.0.0
            Name=mscorlib
            Flags=0x00000000
            Public Key:
  2. Markus W

    Nov 8 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...
    Edited 5 days ago

    Why don‘t you first describe what you want to do? Expecting others to figure out your intentions from rather poorly documented code that isn‘t working properly is … not good.

    I‘m always baffled that programmers aka “presumably somewhat intelligent people” are unable to state problems clearly. For me that indicates a lack of effort, and if they don‘t put the effort in to formulate the problem then I don’t feel inclined to put effort in to find an answer …

  3. Aditya N

    Nov 8 Pre-Release Testers, Xojo Pro

    @Markus W
    Sorry, it's still on prototyping phase but what i am currently trying to do are :

    1. Doing the shell command "C:\Program Files (x86)\Mono\bin\monodis.exe" --assemblyref C:\Users\nameless\Documents\Works\Compiling\Hurricane\Hurricane\bin\Release\Hurricane.exe through the btnshell click and assigned to a "monodis" public property and printed the monodis property value into txtAreaInput.Text
    2. What btnSearch doing are parsing the monodis property through regex, catching all of the the word after the "Name=" and ended before end of line, so for above code the parsing will resulting "mscorlib, "System.Windows.Forms", "System", "System.Drawing" inside result() string array and 'printing' it into txtAreaResult

    I haven't cleaned up the code but here is minimized codes :
    btnShell Action :

    Dim s As New Shell
    Dim cmd As String
    cmd = """C:\Program Files (x86)\Mono\bin\monodis.exe"" --assemblyref C:\Users\nameless\Documents\Works\Compiling\Hurricane\Hurricane\bin\Release\Hurricane.exe"
    s.Execute(cmd)
    monodis = s.Result
    txtAreaInput.Text = monodis

    btnShell result :

    WARNING: The runtime version supported by this application is unavailable.
    Using default runtime: v4.0.30319
    AssemblyRef Table
    1: Version=2.0.0.0
            Name=mscorlib
            Flags=0x00000000
            Public Key:
    0x00000000: B7 7A 5C 56 19 34 E0 89
    2: Version=2.0.0.0
            Name=System.Windows.Forms
            Flags=0x00000000
            Public Key:
    0x00000000: B7 7A 5C 56 19 34 E0 89
    3: Version=2.0.0.0
            Name=System
            Flags=0x00000000
            Public Key:
    0x00000000: B7 7A 5C 56 19 34 E0 89
    4: Version=2.0.0.0
            Name=System.Drawing
            Flags=0x00000000
            Public Key:
    0x00000000: B0 3F 5F 7F 11 D5 0A 3A

    btnSearch Action :

    'Prepare a regular expression object
    Dim myRegEx As RegEx
    Dim myMatch As RegExMatch
    Dim result() As String
    Dim counter As Integer
    Dim temp As Integer = 0 
    myRegEx = New RegEx
    myRegEx.Options.TreatTargetAsOneLine = False
    myRegEx.SearchPattern = "^ +Name=(.*)"
    'Pop up all matches one by one
    //myMatch = myRegEx.Search(txtAreaInput.Text) //In Here the txtAreaInput.Text is always empty
    myMatch = myRegEx.Search(monodis) //In Here the monodis is always empty
    //MsgBox(monodis)
    while myMatch isa RegExMatch
      MsgBox(counter.ToText)
      result.Append(myMatch.SubExpressionString(1))
      counter = counter + 1
      //MsgBox(myMatch.SubExpressionString(1))
      myMatch = myRegEx.Search() // Get the next
    wend
    For temp = 0 To result.Ubound
      txtAreaResult.AppendText(result(temp))
    Next temp

    Current problems are when i am trying to "myMatch = myRegEx.Search(monodis)", the monodis seems being processed as zero/empty input, while doing the MsgBox(monodis) confirmed there are values inside monodis.

    While pasting manually the btnShell result into txtAreaInput field is working fine.

    Should i upload the project file?.

  4. Aditya N

    Nov 8 Pre-Release Testers, Xojo Pro

    Anyone?, i am really baffle by these, because i have did countless debugging and yet the the data is there on "monodis" public property or txtAreaInput.Text but somehow "myRegEx.Search" unable to read it, haven't sure if i need to report it to feedback.

    Anyway, i have upload the project file in here .

  5. Aditya N

    Nov 8 Pre-Release Testers, Xojo Pro

    Seems it's a bug, from debugger or msgbox result are saying the data is intact but somehow regex.search not being able to grab/get data from either properties or textarea.text when the properties or textarea.text are assigned through the code, reported as Feedback Case #54039

  6. Tim H

    Nov 8 Pre-Release Testers Portland, OR USA
    Edited 5 days ago

    Check the hex values from the shell result. You may have a bad character in the string. If I type in the string, it finds all the matches. Also, set the encoding of the string and maybe ReplaceLineEndings, too.

  7. Alberto D

    Nov 8 Pre-Release Testers, Xojo Pro Answer
    Edited 5 days ago

    Hello Aditya, in your code you have lines like this:

    + "Name=mscorlib" + EndOfLine _

    and your search pattern is looking for 1 or more spaces before Name:

    myRegEx.SearchPattern = "^ +Name=(.*)"

    Changing your SearchPattern to "^Name=(.*)" then your sample code works.
    You could add a blank space (or more) before Name too without changing your SearchPattern.

    Edit: are you sure there are spaces before Name and not a tab or two?

    1: Version=2.0.0.0
            Name=mscorlib
            Flags=0x00000000
            Public Key:
  8. Aditya N

    Nov 8 Pre-Release Testers, Xojo Pro

    Really appreciated for your reply, I haven't quite sure on how to add the space into temp variable so instead i deleted it, and now after re-reading it on RegexBuddy you are correct it's different thing for the search pattern, based on @Jean-Yves Pochez replied on this thread changing the search pattern into "Name=([\w|.]+)" make it work, dohhhh, i thought it's a bug, first time experiences in regex part of xojo, feel really ashamed now.

or Sign Up to reply!