r/learnpython • u/Only_Book_995 • Oct 20 '26
Why won't this expression work?
Sorry I know this is probably very basic but I'm a complete beginner:
I'm trying to include "tranexamic acid" and "txa" but exclude the rest
r"(?i)(?<!\w)(?<!not )(?<!no )(?<!consider )(?:tranexamic acid|txa)\b(?!\s+(?:s|not)\b)"
It will find tranexamic acid but not txa
0
Upvotes
View all comments
Show parent comment
2
u/Boybay_Garid Oct 21 '26
this is exactly it, no reason to overcomplicate it when word boundaries handle the hard part already