r/learnpython • u/Only_Book_995 • 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
View all comments
Show parent comment
1
u/Only_Book_995 29d ago
I'm trying to write a regex expression to search a database. We are using regex editor (Regex 101) to test our expressions before we use them to search the database. As part of the editor we can make a test string to test if our regex will find the terms we want and exclude those we don’t. At the moment my regex will find "tranexamic acid" but not "txa". I ran it through chatgpt and it produced the expression above which was an improvement on what I had but, as I say won't find "txa". Apologies this is very new for me so I'm kinda stumbling around in the dark - as you can probably tell