Simple Regex question

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
ChrisF79
Forum Commoner
Posts: 26
Joined: Tue Apr 01, 2008 8:26 pm

Simple Regex question

Post by ChrisF79 »

Greetings:

I'm trying to do a regex on the exprsesion "Foreclosed (REO):</td><td width=240 align=left valign=top>Yes</td>" and trying to capture the word "Yes"

It is always in that format so it should be very easy.

I tried:

Code: Select all

$regex = "/Foreclosed (REO):<\/td><td width=240 align=left valign=top>(.+?)</"
That's what I use to capture other table cells and it works great except this one has the ( character in the description "(REO)" and I think that's what is throwing me off.

Hopefully someone can help!

Thanks,
Chris
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Simple Regex question

Post by pickle »

"(" & ")" are special characters, you'll need to escape them with "\".

Your pattern is overly complex though. This works for me: /top>(.*)</
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ChrisF79
Forum Commoner
Posts: 26
Joined: Tue Apr 01, 2008 8:26 pm

Re: Simple Regex question

Post by ChrisF79 »

pickle wrote:"(" & ")" are special characters, you'll need to escape them with "\".

Your pattern is overly complex though. This works for me: /top>(.*)</
Well, I tried escaping them with \ and that didn't work either for some reason. And as far as it being overly complex, it has to be because there are literally 200+ fields in this table and they almost all have the valign="top" part at the end. I definitely need to use "Foreclosed (REO)" somewhere in the expression.

Thanks though.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Simple Regex question

Post by prometheuzz »

ChrisF79 wrote:
pickle wrote:"(" & ")" are special characters, you'll need to escape them with "\".

Your pattern is overly complex though. This works for me: /top>(.*)</
Well, I tried escaping them with \ and that didn't work either for some reason. And as far as it being overly complex, it has to be because there are literally 200+ fields in this table and they almost all have the valign="top" part at the end. I definitely need to use "Foreclosed (REO)" somewhere in the expression.

Thanks though.
Try posting the actual data you're testing your regex against, and also post the regex you're using of course.
Just saying "it didn't work either" isn't nowhere near specific enough for others to be able to help you.

Good luck.
Post Reply