Forum Moderators: coopster

Message Too Old, No Replies

preg match all challenge

stuck with regex

         

phparion

7:54 pm on Jan 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi guys,

{tag1}#*$!x{p}ssss{/p}{/tag1}
{tag1}#*$!x{p}ssss{/p}{tag1}
{tag1}#*$!x{tag1}
{tag1}#*$!x{p}ssss{tag1}#*$!xx{/tag1}{/p}{/tag1}

what i am interested is the value that appears with in tag1-pair and SKIP p-tag value IF it does not have a tag1-pair inside it, if it is found then fetch that as well.

additionally, it is possible that tag1 is incorrectly closed, in that case i must end my search on finding an opening tag1 without closing the previous and make a separate array of such strings so that i can fix those values.

i tried so many things with lookahead and lookbehind assertions with backreference. but in vain. before i go to a php solution i wanted to know if anybody here can solve this with regex.

coopster

7:00 pm on Apr 20, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A recursive regex modifier seems to be in order here but a preg_replace_callback may be useful too. It's been some time since you posted this, phparion, did you come up with a working solution?