RegExMatch is always NIL?

In the following code, no matter how I address my variable “theMatch”, it’s always NIL. I am sure that the jobData() array contains valid strings as expected by the RegEx filter.

myRegEx.SearchPattern = "^(\\w)\\x20+(\\S+)\\x20+(\\S+)\\x20+(\\S+)\\x20+(\\d+)\\x20+(\\S+)\\x20+(\\S+)\\x20+(\\d+)\\x20+(\\w+\\x20+\\d{1,2}\\x20+(?:\\d{4}|\\d{2}:\\d{2}))\\x20+([^\\r\ ]+)" If jobData(x).LeftB(1) = "i" Then Dim theMatch As New RegExMatch theMatch = myRegEx.Search(jobData(x)) If theMatch.SubExpressionCount > 0 Then // <- theMatch is always NIL For y = 0 To theMatch.SubExpressionCount - 1 bruLine.Append theMatch.SubExpressionString(y) Next End If Else bruLine.Append(jobData(x)) End If

In light of my using the New operator in the above case, how can it be NIL? Any ideas?

Xojo Windows 14r3.2

It’s nil because the Search method returns Nil when it doesn’t find a match.

Have you tried your pattern in something like Kem’s RegExRx? Just skimming your pattern, I’m not sure it would match if the leftmost character were an “i”.

We’ve validated the search expression (it was created with Kem’s RegExRx app and his help) and the strings in jobData() are valid for the match.

  • taking it further, I found one scenario where a Windows system could return the line without the file/path component. I’ve added a trap for that and all is now functioning as expected on all three platforms.

What was catching me was that I was confused that theMatch could be Nil even thought I’d used the New operator.

The use of the New operator is wrong, or at least superfluous.

Dim theMatch As New RegExMatch            // allocates an object
theMatch = myRegEx.Search(jobData(x))   // throws it away and replaces it with the result of Search

Yep - and it has been removed. I inserted it to try and determine why the Nil was occurring.

[quote=162661:@Tim Jones]In the following code, no matter how I address my variable “theMatch”, it’s always NIL. I am sure that the jobData() array contains valid strings as expected by the RegEx filter.

myRegEx.SearchPattern = "^(\\w)\\x20+(\\S+)\\x20+(\\S+)\\x20+(\\S+)\\x20+(\\d+)\\x20+(\\S+)\\x20+(\\S+)\\x20+(\\d+)\\x20+(\\w+\\x20+\\d{1,2}\\x20+(?:\\d{4}|\\d{2}:\\d{2}))\\x20+([^\\r\ ]+)" If jobData(x).LeftB(1) = "i" Then Dim theMatch As New RegExMatch theMatch = myRegEx.Search(jobData(x)) If theMatch.SubExpressionCount > 0 Then // <- theMatch is always NIL For y = 0 To theMatch.SubExpressionCount - 1 bruLine.Append theMatch.SubExpressionString(y) Next End If Else bruLine.Append(jobData(x)) End If

In light of my using the New operator in the above case, how can it be NIL? Any ideas?

Xojo Windows 14r3.2[/quote]
Tim could you also list your source data so i can apply your pattern to it?

Thanks

By the way, are you setting the encoding of the text before doing the regex search?