Secret sauce for RegEx??

Hi. Not new to Xojo, but really new to RegEx.

Searching the string Batch Report 20120724.pdf
Using regexr.com and the expression: b\w+[/b]
On regexr.com, it finds: 20120724 which is what I’m looking for.
When I enter the same strings into the RegEx in Xojo, it returns no results.

Any help would be appreciated.

Thanks,
Gary

as far as Xojo, this forum and RegEx is concerned… there is only one source of secret sauce :slight_smile:

Kem Tekinay

works fine to me:

[code]
Dim rg As New RegEx
Dim rgm As RegExMatch

rg.SearchPattern = “([0-9])\w+”
rgm = rg.Search(“Batch Report 20120724.pdf”)

Dim n As Integer

Do
If rgm<> Nil then
TextArea1.AppendText rgm.SubExpressionString(0)+ EndOfLine
n= n+ 1
End if

rgm= rg.Search

Loop Until rgm= Nil

TextArea1.AppendText EndOfLine+ " matches:"+ Str(n)

Exception err As RegExException

MsgBox(err.Message)[/code]

Shows 1 matches: 20120724.

Just out of curiosity, since that number seems to represent a date, would it not make more sense to use this pattern?

([0-9]{8})

Thanks Bernardo and Greg. It does work, Bernardo. My problem was a very complicated set of code on my part that caused it to be difficult to find the issue of using the wrong TextFields. Put in the simpler code and it was easy to find & fix it.

Greg, the ([0-9]{8}) usage would work but not all of these dates are 8 characters with no hashes. The goal is to find 20120724 or 201207 or just 2012. As I’m reconstructing these dates into actual SQL date strings, getting the parts of the date, so the original SearchPattern works best for me.

Thanks again, Guys.

Gary

Ah, then {4,8}.