Chel MS
Chel MS

Reputation: 466

Python regex - match starting from numeric character

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.

Upvotes: 0

Views: 34

Answers (1)

Sebastian
Sebastian

Reputation: 6057

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']

Upvotes: 1

Related Questions