Search code examples
pythonregexparsingdigits

Python3 Regex for extract digits


I try to extract digits from urls with Python.

import re

url = '/randomtext/02@randomtext/01@randomtext/03@randomtext/01@.mp4'
for m in re.finditer(r'\d{2}', url):
    print(m[0], end='')

print function do this but I need the same result in variable, how can I did this?


Solution

  • s = "".join(m[0] for m in re.finditer(...))