Re:The Greatest Regex Trick Ever (2014)
by PennRobotics on Friday July 09, 2021 @06:57AM
(#27782395)
If you are comparing the match to the wanted string, it defeats the purpose of the capture group.
if "tarzan" == re.search(r'"tarzan"|tarzan', myvar)[0]:
...
Am I missing something?Is there a reason you have an r-string for the first arg but not for the third one?
Re:The Greatest Regex Trick Ever (2014)
by alisonkisk on Thursday July 08, 2021 @08:21PM
(#27779217)
It's a harmless mistake.
sadly, this trick still requires a code comment to explain. Python example:
which in practice means it probably deserves a function: I don't recommend monkeypatching re, i.e. re.search_but_exclude = ...