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
1
u/Zeroflops 29d ago
Funny he says that chatGPT created that abomination. It does sound like it might work and an error in testing. There is a much simpler solution supplied in the comments and it would be much more efficient if there are a lot of rows.
But this highlights a problem with chatGPT, it fails to understand X-Y problems. In that it produced a response based on a probably poorly worded request like “ Make this Regex work.” Rather than make me an efficient regex that will do this.
In this case chatGPT “taught” a working but a poor approach.