Basically I have these strings and I'm programming on Python 3.9 :
'P425-TK-1501'
'P425-UN-1840'
'P900-TP-1001'
What if I want to match each of these strings EXCEPT the one with TP
(P900-TP-1001
).
As you can see, my challenge here was to INCLUDE the P425-TK-1501
but EXCLUDE P900-TP-1001
I tried excluding but it doesn't seem to work with what I need.
[UPDATE] So basically, I've written a code to extract specific strings within a txt file. In the text file, there are words, numbers, spaces, etc. The strings I want to extract have specific format which is searched using this Regex : '[BPC][3-9]\d{2}-[A-Z]{2}-[1-2]\d{3}' .
What it does :
- Searches for B, P or C for the first character.
- Searches for number from 3 to 9 for the second.
- Searches for any number for the third & fourth.
- Searches for a hyphen for the fifth.
- Searches for a letter from A to Z for the sixth and seventh.
- Etc...
What I would like, is for the Regex to EXCLUDE the specific strings 'TP' (in that order), WITHOUT excluding 'TK' which may occur multiple times in the text file.
To exclude a substring, simply accept the strings which do not have it. No regex needed.
produces