Regex woes…

I have come up with this regex:

^.*[[:<:]]T[[:alnum:]]* [[:<:]]P[[:alnum:]]*.*$

(yes, it’s old-style ereg syntax for use in a MySQL statement)

In PCRE syntax it’d look like:

/^.*\bT\w* \bP\w*.*$/i

It will match ‘T P’, ‘Tony P’, Tony Parsons’, ‘Some Tiny People’…

So far so good. Unfortunately I need to find a way to tell it NOT to match certain words, such as ‘The’.

i.e. it should match ‘Theremin Player’ and ‘The Tree Party’, but not ‘The Pastors’ or ‘Tony The Pony’.

Continue reading “Regex woes…”