Jump to content

does not match pattern


GoneNowBye

Recommended Posts

okay i'm gonna simplfy it here, hence lack of codes, i've made some sort of markup language, rather then try and explain it, i'll just use html.

 

lets say i'm trying to parse html and i have

 

<div id="this">

</div>

<div id="that">

</div>

 

and you tell regex to match

(?:<div )([A-Za-z0-9= "_]*)>([\\[\\]=" ->a-zA-Z_]*)(?:</div>)

its fine but it matches

</div>

<div id="that">

 

not each div tag seperatly, how may i specify to REGEX dont match the end one match the ones between

Link to comment
https://forums.phpfreaks.com/topic/206751-does-not-match-pattern/
Share on other sites

You can parse HTML with Regex, it is just generally not the best way. Normally far easier/simpler to use some kind of DOM. It sounds like what you are talking about is the difference between Greedy and Lazy pattern matching. By default a PCRE pattern is greedy, you need to make it lazy.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.