Hi there,
while I consider myself of good knowledge concerning RegExp, I'm in need of a RegExp that matches any content between two matching tokens, where the content in between can contain those tokens as well.
An easy example would be matching
[FONT=courier new]<td>[content]</td>[/FONT]
with nested tables (and thus with <td></td> as well) in mind.
Another would be
[FONT=courier new]if (...) {[content] }[/FONT]
again, with nested if - Statements in mind.
Detailed example:
[FONT=courier new]
if () {
echo 'something';
if () {
echo 'nested statement, matched as well';
} else {
echo 'else branch';
}
echo 'another thing';
// ...
}
if (...) {
echo 'content continues outside the match';
}
[/FONT]
where the RegExp matches everything highlighted in red.
The logical approach would seem to match all content until there are more closing tokens than opening tokens within the match and then stop.
I'm pretty sure this is doable with RegExp (BackReferences seem a good approach) but so far I haven't figured out how, so any help would be greatly appreciated.
Thanks in advance,
Sal-