I’m trying to parse data from an FDF file exported from a PDF form, and the Regular expression I am using works fine when I’m testing in an external editor, but I don’t get any matches when run in my application (I’m using an older RealStudio version)
The expression I’m using is
<</T\(([^<>])\)/V\(?([^<>])\)?>>
When I copy the string from the debugger, and paste it into the program which I use for writing and testing regular expressions, the expression works as expected and produces the 12 expected matches. I’ve used Regular expressions in my program in multiple places, and never had any issues getting them to work with an expression which had tested correctly.
This is the code I am using which is producing no matches (match is nil):
[code]Dim re As New RegEx
Dim match As RegExMatch
Dim result As String
re.SearchPattern = “<</T\(([^<>])\)/V\(?([^<>])\)?>>”
match = re.Search(s)
Do
If match <> Nil Then
result = match.SubExpressionString(0)
End If
match = re.Search
Loop Until match Is Nil[/code]
I copied this directly from the LR, and it worked with the example parameters from the LR. I can’t see why it doesn’t work in the program when I use the values which worked elsewhere. I’ve tried setting the RegEx.options, but no success.
I’m using ‘The Regex Coach’, which I’ve been using for years, and never had any different results. I believe the default settings in that program match the defaults in RS/XOJO, but I’l check that. Not sure which option(s) could have any effect in this case.
I’ll try that, thanks. I’m wondering if it could be an encoding issue or something. I’ll also try hard coding the text string into the function variable for now to see if it works that way.
I’d try Kem’s program, but I’ve been using this one for so long now (since before I started working with RS/XOJO) that I feel comfortable with it.
The match works properly when I paste the text into a string constant, but not the text that is read from the file. Not sure what the encoding is, I’ll have to check that now. What threw me is that in the debugger, I can copy the text from the variable, and that was what I was using to test.
Solved. I was originally reading in the entire file at once, and apparently there are a few characters in the second line which aren’t showing up here (or in the debugger). Apparently, these characters are causing the problem.
When I read the file in by line, it works as expected.