Thanks again for the help. It certainly solved the first issue.
I am still struggling with getting the roRegex to work properly for my needs. I am basing it on a piece that was previously used in PHP, so that may be the issue. I wanted to double check that it was not a possible bug. Because no matter how I approach it, I am still not receiving any results.
Here is the “string” I am loading in. I am certain the data is reaching the code, as this is a copy and paste from the actual print statement:
Here is the code responsible for parsing the “string” returned from a AsyncGetToString call:
strResult = msg.GetString()
'printing the string result works just fine
print strResult
match_exp = "!<form.*?action=" + Chr(34) + "(.*?)" + Chr(34) + "!"
regex = CreateObject("roRegex", match_exp, "ims")
arr = regex.Match(strResult)
'always contains invalid at any position
print "ismatch->";arr[1]
The result is always “invalid”, though it should be the value of the “action” attribute. This is the case for any other array slot as well.
Admittedly, I am not very well versed with regular expressions. But as mentioned, it does work in my exsisting PHP script.
You might want to make it match only spaces, carriage returns and line feeds, rather than any characters, between the = and the quote. You might end up matching a bunch of unrelated text between the = and the quote, which isn’t what you want.
Also, I haven’t tried this but it doesn’t seem like the question marks should be necessary. “.*” already matches zero or more characters, so the following question mark doesn’t do anything.
Thank you for the tips. Again, I am not very familiar with regex (but learning quickly now :mrgreen: ) so every bit helps.
Since we are on the subject of roRegex, I was trying to figure out an approach to emulating the preg_match_all
I was hoping someone might point me the right direction. I don’t mind trying to figure it out, if there isn’t a quick answer, but I’m certainly scratching my head on the best starting point. I am assuming a mixture of Parse and Match, with possibly an Array to “tear” pieces of the string out of. I’ll certainly share whatever I find, if I can at least get heading in the right direction.
Thanks again! I’m hoping that this information might be useful in the future to others, as well as myself.
“RokuMarkn” wrote:
“.*” already matches zero or more characters, so the following question mark doesn’t do anything.
The question mark makes the match “lazy”, so it doesn’t go crazy and keep matching characters past the first double quote it sees. It may or may not be necessary in this case, but it seems safer.
“mainmanc” wrote:
Since we are on the subject of roRegex, I was trying to figure out an approach to emulating the preg_match_all
Assuming you just want to capture every matched value, there may be a simpler way, but this is the brute force method I used… this does modify the original string, so you may want to use a copy instead.
values = []
matches = regex.Match( response )
iLoop = 0
While matches.Count() > 1
values.Push( matches[ 1 ] )
' remove this instance, so we can get the next match
response = regex.Replace( response, "" )
matches = regex.Match( response )
' if we've looped more than 500 times, then we're
' probably stuck, so exit
iLoop = iLoop + 1
If iLoop > 500 Then
Exit While
End If
End While
Function MatchAll (pattern As String, subject As String, flags As String) As Object
regex = CreateObject("roRegex", pattern, flags)
response = Left(subject, Len(subject))
values = []
matches = regex.Match( response )
iLoop = 0
While matches.Count() > 1
values.Push( matches[ 1 ] )
' remove this instance, so we can get the next match
response = regex.Replace( response, "" )
matches = regex.Match( response )
' if we've looped more than 500 times, then we're
' probably stuck, so exit
iLoop = iLoop + 1
If iLoop > 500 Then
Exit While
End If
End While
Return values
End Function
Posting the same question in two places just makes it harder for people to find answers in the future. Polluting the forum with unnecessary posts to get your own questions “more exposure” in not appropriate. I am closing this thread.