I need to make a regex which matches content between tags like this:
<tag>
<b> Match Me </b>
</other-closing-tag>
It should match only the content between the same tag. So the result should be something like this:
1 match:
<b> Match Me </b>
Match me
And I need to do it in PHP, but I don’t think that this is that important…
Use regular expression back references, which you can read more about under the following link.
Though parsing html with regular-expressions is never a good idea, but I’m going to pretend that you are going to use this information for a completely different problem. 😉
Example snippet
In the below we are saying that the contents of our end-tag should be the same as what is matched by our first group
([^>]+), by using\1inside our closing tag.output