Reputation: 4606
I am trying write a regex to get last digit.
My string: name[0][0].
My regex: str.match(/d+/g)
It return all match. Can you help me make regex return only last match?
Upvotes: 0
Views: 1260
Reputation: 174696
To get the last digit,
\d(?=\D*$)
To get the last number.
\d+(?=\D*$)
\d+
matches one or more digits. +
repeats the previous token or more times. (?=\D*$)
called positive lookahead assertion which asserts that the match would be followed by any number of non-digit characters further followed by end of the line.
Upvotes: 2