Re:The Greatest Regex Trick Ever (2014)
by Tipewryter on Thursday July 08, 2021 @03:21PM
(#27776551)
The solution...
... is interesting. But since it returns the match in a submatch I would say the \K approach is better:
Because usually when you try hard to accomplish something with a regex, you do not have the luxury to say "And then please disregard the match and look at the submatch instead".
[ Parent
| on HN ]
Re:The Greatest Regex Trick Ever (2014)
by lifthrasiir on Thursday July 08, 2021 @03:37PM
(#27776691)
That doesn't work. `(?:"Tarzan".*?)*\KTarzan` should behave identically without `\K`, and it will match `"Tarzan" "Tarzan"` because the ungreedy quantifier ? still allows backtracking (it just changes the search order). You want the possessive quantifier + instead; `not_this|(but_this)` is equivalent because regexp engines will not look back into once matched string.
Re:The Greatest Regex Trick Ever (2014)
by Tipewryter on Friday July 09, 2021 @02:17AM
(#27780930)
Interesting. I took the \K solution right from the article without trying it.
Now that I try it, it indeed does not work.
Maybe the author reads this and can look at it.