ISO regex guru for help in multi-line pattern match
Hi!
I'm hoping there is a regex guru in the house. I've been getting pretty good at this on a novice level and now it's time to step up the game a little bit.
From this little section of HTML code below I'd like to pull the addresses out. I tried this:
Alas .. my results yield nothing =( I don know that the end of each line in the HTML is a LF not CR/LF. I did try using the s modifier instead of the m. Still no luck! Oh .. I'm using preg_match_all and not just preg_match
I've seen multi-lines done but it was congested with \/.*+ and other thing I couldn't follow it. If you could please help me with this one and break it down for me so I can under stand what is going on. I think once I get this one under my belt and I can follow it I can do others.
Hope you can help! I'll consider if an xmas present! =) Probably the only one I'll be getting this year!
__________________
“No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.” ~ Mark Gibbs
Tim is right, using the DOM is a lot more reliable than regular expressions for parsing HTML. That being said, I believe something like this is what you're looking for:
A little tip for you: .* is almost always a bad idea. finding "margin-bottom:.*?>" - "margin-bottom:[^>]*>" leads to less confusion and errors.
I use "The Regex Coach" from http://weitz.de/regex-coach/ for developing and testing complex expressions, I strongly recommend it. The Windows version runs perfectly in Wine too.
Tell me if I'm right or not! This <div[^>]*>[^<]*</div> after the <div but not a > 0 or more time then a > and again not a < 0 or more times the a </div>
Now does \s* mean more then one space, tab or line break
I'm confused on this one: <br[^>]*>[\s\r\n\t]*([^\r\n\t]*?)
Dumb question is .. how to you train your brain to think this way? I just haven't found the in's and out's of it yet. If I had a good teacher I'd be better off. I'm semi-noobish so go ahead and beat me up!
__________________
“No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.” ~ Mark Gibbs
This <div[^>]*>[^<]*</div> after the <div but not a > 0 or more time then a > and again not a < 0 or more times the a </div>
Correct.
Quote:
Originally Posted by MrBiggZ
Now does \s* mean more then one space, tab or line break
I'm confused on this one: <br[^>]*>[\s\r\n\t]*([^\r\n\t]*?)
Yeah, you don't really need \r\n\t in that one. I left them in there because I added the \s last, and... lazy.
Quote:
Originally Posted by MrBiggZ
Dumb question is .. how to you train your brain to think this way? I just haven't found the in's and out's of it yet. If I had a good teacher I'd be better off. I'm semi-noobish so go ahead and beat me up!
You seem to have a better knowledge of regex than most people that ask questions about it. As far as getting your brain to think like that... I'm not sure. The easiest way I have found to develop/test regular expressions is to use Regex Buddy(commercial). I have used The Regex Coach mention earlier previously, and it's a good free solution, but Regex Buddy is the best piece of software I've used for regex thus far.
Yes sir I've seen Regex Buddy but my wallet cried at $40 bucks. I guess if I was doing this for a living .. it would be a good investment. But I mainly do this just to keep my mind sharp and that degree that hangs on the wall behind me that has NEVER been used to some use. =((
Cobol programmer by schooling. When I graduated in '88 PC were about were a POS used car costs now. The interwebz didn't even exist in the civilian world yet.
I guess it's going to have to be repetition learning to get this down. *sigh*
Thanks for all your help!
__________________
“No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.” ~ Mark Gibbs
Thanks bud! Haven't ran across that one yet! Once the torture, I mean holidays are over I'll have to apply myself a bit more on it! Consider it bookmarked!
__________________
“No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.” ~ Mark Gibbs