I’m currently fighting a weird javascript regex problem. I’m trying to match all characters between / or the end of input. For example this string
admin/item/get
should be matched as:
[ 'admin', 'item', 'get' ]
I don’t really care if / is part of the match or not, so this result would work for me too:
[ 'admin/', 'item/', 'get' ]
To match the input string s I’m using the regex
s.match(/.+?[\/$]/g)
which results in
[ 'admin/', 'item/' ]
To my understanding the end of input $ is not matched in this character set.
When I try to match only the end of input using the regex s.match(/.+?$/g) I’m getting the expected result [ 'admin/item/get' ]. But placing the $ in a character set s.match(/.+?$/g) the match call returns null.
Any help appreciated…
Btw: I’m using node.js 0.8.20
Because
$is treated as a character when placed inside a character set. This should do it though, it uses an alternation inside a non-memory capturing group and thus restores the meaning of$to be the end-of-subject:As mentioned in the comments: