The end of the line does not work in the character class, because it is not a character. This is a zero-width statement (it checks the condition at the current point in the line, but does not actually use a character).
Test it with (?:otherstuffhere|$) .
Note. It seems you are mixing a character class with the corresponding subgroup. A character class [...] matches any character in brackets. [a|bc] will match either a , | , b , or c . Relevant subgroups are what you want or multiple expressions. (...) is the corresponding subgroup with capture. (?:...) is the corresponding subgroup without capture.
Note that the $ matching behavior may vary in a multi-line string based on your settings. It can either match the end of each line, or just the end of the line.
\z will always match only at the end of a line, no matter what settings you use. \z will match either at the end of a line or just before a new line at the very end.
user1919238
source share