简体   繁体   中英

Regex with last match only

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?

To get the last digit,

\d(?=\D*$)

To get the last number.

\d+(?=\D*$)

DEMO

\\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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM