Tuesday, 15 May 2012

Regex match last whole number -



Regex match last whole number -

i need extract lastly number strings like

10-20 days // should extract 20 10 30 days // should extract 30 between 5 , 12 days //should extract 12

iv tried pattern ^.+([0-9]+)[^\d]days.$ takes lastly digit not whole number.

you utilize positive lookahead assertion.

\d+(?=\d*$)

explanation:

\d+ digits (0-9) (1 or more times) (?= ahead see if there is: \d* non-digits (all 0-9) (0 or more times) $ before optional \n, , end of string ) end of look-ahead

regex numbers range

No comments:

Post a Comment