Regex crisis...
October 30, 2008 10:02 AM Subscribe
Regular Expressions / PHP preg_replace problem. Can this be made to work...?
I've got a long string of text that will contain something like this...
<container>aa<alpha>t</alpha>bb<beta>i</beta>dd</container>
I want to have a nice little bit of regex that plucks the 't' from alpha and the 'i' from beta. In itself okay. Except I want it to match correctly if it finds
<container>aa<beta>i</beta>bb<alpha>t</alpha>dd</container>
and for it to get what it can if someone misses a field, like this...
<container>aa<alpha>t</alpha>bb</container>
My basic knowledge of regexes suggests the following should have worked, but as you can guess from my question, it doesn't.
@<container>([^<>]*)((<alpha>(.*?)</alpha>)|(<beta>(.*?)</beta>)|(^<>]*?))*([^<>]*)</container>@mi
Help...?
posted by twine42 to computers & internet (13 answers total)
posted by niles at 10:22 AM on October 30, 2008