I was doing a regex golf the other day, and the task was to match 'u' at the end of the string without using $
. The goal was to match "fu", "tofu" and "snafu" but not "futz", "fusillade", "functional" or "discombobulated".
I came up with fu[^tsn]
, which worked on regex101; however, it does not pass the test as it does not match any of "fu", "tofu" and "snafu" for some reason. I'd like to know why it is not working, and if there is a smarter way to work around this (bonus: is there any real-life situation where not using $
would be better).