I want a regular expression to match all strings like 'T' OR 'T-Th' but NOT values containing only 'Th'
my current regexp is this one:
REGEXP = '[T-Th]'
but it matches all strings 'T' , 'T-Th' and 'Th' which 'Th' is not desirable
REGEXP = '(T-Th|T[^h])'
We either match T-Th literally, OR match T that is not followed by anything but an h. In other words: T, T-Th, but not Th.
The - character between brackets is special for regex. It must be escaped when the use is literal. A good alternative for your problem could be this:
REGEXP = '(T-Th|T(?!h))'
- is only special inside a character class.
[T-Th]is the same as[Th](which matches T or h, not "Th").TorT-Th, rather than words beginning with or containingTorThas the[]character kind of implies?