"jbrave" wrote:
I've had way more success using string functions like instr, mid left and right than regex. I posted a regex I found for parsing HTML a while ago, but have never actually gotten it to work beyond giving me the string "<HTML>" so if anyone has some code that works to get a specific tag or an associativearray of tags it would be awesome.
The trick is to use lazy operators (instead of greedy ones, which are the default). You get lazy operation by appending "?" to a match multiplier.
e.g.
With the string "<b>this is a bold string.</b> <i>this is an italicized string.</i> <b>this is another bold string</b>"
With this content, the regex "<b>.*</b>" will match from the
first <b> to the
last </b>, which generally isn't what you want.
If you change the regex to "<b>.*?</b>" you get a "lazy" match between the opening and closing bold tags, which tries to match the
minimum possible, instead of the
maximum possible, with the maximum possible match being the default behavior of + and * (and ? when used by itself).
That said, there are other problems commonly encountered. using a regular expression to parse HTML is problematic in most cases. You really need to be able to make some assumptions about the specific content you are parsing.
-- GandK Labs
Check out Reversi! in the channel store!