Reputation: 86905
How can I tell to match everything up to a specific character set, or EOL?
[=]+.*?[()|$]
matches: ==test)
does not match: ==test
Why is the end of line regex anchor $
not taken into account for the 2nd statement?
Upvotes: 4
Views: 213
Reputation:
End of line does not work in a character class, because it is not actually a character. It is a zero-width assertion (it tests a condition at the current point in the string, but doesn't actually eat up a character).
Test for it with (?:otherstuffhere|$)
.
Note: you seem to be confusing a character class with a matching subgroup. A character class [...]
matches any one character within the brackets. [a|bc]
will match either a
, |
, b
or c
. Matching subgroups are what you want to OR multiple expressions. (...)
is a matching subgroup with capturing. (?:...)
is a matching subgroup without capturing.
Note that the matching behavior of $
can vary in a multi-line string based on your settings. It could either match the end of each line, or only the end of the string.
\z
will always match at the end of the string only, no matter what settings you use. \Z
will match either at the end of the string, or right before a newline at the very end.
Upvotes: 5