Well, I’m doing an exercism.io exercise that involves recreating a subset of Forth.
One of the test requirements is that non-word characters are separators between tokens, such that:
"1\x002\x013\n4\r5 6\t7" == "1 2 3 4 5 6 7"
But the exercise involves building a toy language that can do subtraction, so I need a way to distinguish between hyphens used to separate word characters and hyphens used as subtraction symbols:
"1 2 + 4 -" == "1 2 + 4 -"
So actually, what I need to represent in a regex is “all non-word characters EXCEPT a hyphen on its own.” This question was just to unstick me on that last part, finding the hyphen on its own.






















