RegEx does not find matches

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\(?([^<>])\)?>>

and the string:

[quote]%FDF-1.2
%
1 0 obj
<</FDF<</F(Entry Form.pdf)/Fields[<</T(AccountExecutive)/V(John
Doe)>><</T(Brand)/V(Brand Name)>><</T(Coordinator)/V(Bill
Smith)>><</T(Date)/V(10/21/2015)>><</T(FileNames)/V(TestFile.zip)>><</T(JobN
umber)/V(12345)>><</T(Notes)/V()>><</T(Promotion)/V(Easter)>><</T(Type)/V(Po
int-of-Purchase
\(POP\))>><</T(Year)/V(2016)>><</T(cbEmailAE)/V/Yes>><</T(cbEmailCoordinator
)/V/Yes>>]/ID[<79C53DFBA262ABCC3F1BBF5C3EAFF333><11EA57129347425A85F64E3B66A
56936>]/UF(/Entry Form.pdf)>>/Type/Catalog>>
endobj
trailer
<</Root 1 0 R>>
%%EOF[/quote]

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.

Not knowing what external tool you use I’d double check that the options are the same in it and your instance in your code

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 just tried RegExRX with your pattern and string and it works fine. Kem wrote RegExRX in Xojo so it shows it does work.

The nice thing about RegExRX is that it can give you native Xojo code:

dim rx as new RegEx
rx.SearchPattern = "(?mi-Us)<</T\\(([^<>]*)\\)/V\\(?([^<>]*)\\)?>>"

dim match as RegExMatch = rx.Search( sourceText )

Try that and see what it gives you.

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.

That’s the issue.

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.

Thanks Norm and Jon for the assistance.