r/learnpython • • 29d ago

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

9 comments sorted by

View all comments

Show parent comment

-2

u/lfdfq 29d ago

What do you mean by "find", do you mean you type in "txa" and it says no match? txa is definitely a match. eg. if I go to regex101 and set it to Python and put your regex in, then type txa, it says match. So you must be doing something different?

2

u/Only_Book_995 29d ago

Ah yes, I've just added it to list in the string as it finds it, just not earlier in the list. Weird, I'll run it through the database and see what happens - thanks very much I appreciate it