Home > database >  Python regex - match starting from numeric character
Python regex - match starting from numeric character

Time:10-07

Input

abc-preview-check-random-post-5.500.510-5009
abc-preview-check-random-post-2.15.510-50098709

Expected output:

5.500.510-5009
2.15.510-50098709

I tried [^a-zA-z] but its matching the dashes as well.

CodePudding user response:

A working regex could be: \d.*$

import re
p = re.compile('\d.*$')
p.findall("abc-preview-check-random-post-5.500.510-5009")
# ['5.500.510-5009']
p.findall("abc-preview-check-random-post-2.15.510-50098709")
# ['2.15.510-50098709']
  • Related