I am trying to use regex to capture all the <div> and <span> tags in to a PHP array.
My code for getting single tag is:
[#<div>(.*?)</div>#i]
Single is not a problem, but im stuck trying to select two tags at once. My attempt is as follows:
[#<div>?<span>?(.*?)</div>?</span>?#i]
Any help will be appreciated.
Would a regex like this work for your purposes?
The first and third capture groups would tell you the type, and the 2nd would contain the info you want to capture. Not sure what you mean by “select two tags at once” however… maybe nested?
http://rubular.com/r/ojYJjXFMZt
Using a proper parser is probably the way to go however as Ranhiru Cooray suggested.