Regular expressions are full of features (who can learn it all? or read off and understand a few days after it was written?). One of them is possibility to check if desired match is followed or preceded by given pattern.
It works also in PHP.