I’ve got this pattern which I use with preg_match and I can’t figure where I go wrong.
$pattern = "{(\[fn:)([0-9]*)(\])((?:\\\[|[^\[])*)}";
It has to match each [fn:i]text_multiline untill another one starts so when it meets [ and i want to escapte the [ by \[ from the following example:
[fn:1] This is the text for \[this needs to be escaped] footnote 1.
Note that it could be multiple paragraphs.
[fn:2] This is the text for footnote 2.
This is the matches that I get at the moment:
array(5) {
[0]=>
string(6) "[fn:1]"
[1]=>
string(4) "[fn:"
[2]=>
string(1) "1"
[3]=>
string(1) "]"
[4]=>
string(0) ""
}
The technique to use when you want to exclude and escaped [ is called “negative look behind”.
For example,
This regex will match [ but ignore if its proceeded by a \
Let me know if you need any more help
Edit #1
This is the negative lookbehind applied to your specific scenario
and in php this becomes
Some notes
The regex is tested against your example. Let me know if you can get it working now
Good luck, Buckley