Regex How to match everything after last occurance, but not including the matched character
I have a string, for example:
black-guitar-12-strings-7584
And I am trying to match t开发者_如何学Pythonhe set of digits at the end (not always 4 in length).
So far I have:
(-)[^-]*$
Which matches the last part but I don't want to include the last hyphen also.
Any ideas? thanks.
Try this pattern: \d+$
or [0-9]+$
. It matches last sequence of digits.
Just omitting it would work: [^-]+$
For more complex issues then this one you could also look at lookahead / lookbehind, but those aren't necessary here.
If you want to match everything after the last "-", this will do it:
[^-]*$
(\d+)$
should work. if you have more than just digits, you could use something like
-(.+?)$
I added capturing because I assume that's what you want. it uses a non-greedy quantifier, which will match the minimum.
精彩评论