Reputation: 502
I want to match the trailing hyphen, but using the expression [0-9]|-$
matches even if the string contains only one hyphen. How can I correct it?
Existing behavior
-
#match (incorrectly working for me)-5-
#matching trailing hyphen only (correctly working for me)Expected behavior
-
#shouldn't match5-
#should match trailing hyphen (only "-" not whole "5-" )Upvotes: 1
Views: 163
Reputation: 786291
You can use lookbehind in Javascript to assert presence of a digit behind a hyphen using this regex:
/(?<=[0-9])-/g
Upvotes: 2