I have the following string:
OPEN someone said hello CLOSE im saying hello people OPEN some said hello OPEN they said hello again CLOSE i have to go now though CLOSE hello again!
I'm trying to match all occurences of hello (that are not enclosed in the OPEN and CLOSE words) and replace them with another word, possibly with a regex and PHP's preg_replace
function (although I'm open to other methods as I can't think of any).
So from the above string the below will match (I've placed them in brackets with italics to help you distinguish):
OPEN someone said hello CLOSE im saying (hello) people OPEN some said hello OPEN they said hello again CLOSE i have to go now though CLOSE (hello) again!
Not really sure how to go by doing this.
Edit perhaps this will clarify the nesting structure abit better:
OPEN
text
CLOSE
OPEN
text
OPEN
text
CLOSE
text
CLOSE
As you can see from above, the hello is not being notice because its within OPEN...CLOSE (so they are ignored) whereas the others which arent are going to be replaced.