i’m using
preg_match_all('/<?(.*)?>/', $bigString, $matches, PREG_OFFSET_CAPTURE);
to find the contents of everything between <? and ?>
Now I’d like to find everything that is NOT between <? and ?>
I’m trying with
preg_match_all('/^(<?(.*)?>)/', $bigString, $nonmatches, PREG_OFFSET_CAPTURE);
but that doesn’t seem to work…
Well, there are multiple approaches to this issue. One way is to capture the items you want to exclude, find their offsets and lengths and basically just extract those parts out from the original string and all you’re left with are the parts outside the tags.
Here is a function as an example:
Alternatively, you can use this regular expression
/\G(?=.)((?:(?!<\?).)*)(?:<\?((?!\?>).)*(\?>|$)|$)/sinpreg_match_allto capture all the parts outside the tags into the sub pattern one. Although, it may have it’s own difficulties, if the tags are not evenly matched in the document.For example,