I’m trying to get two separate regex matches of a string:
a = " practicing_regular_expressions_z1_test_y3_test_y11_1930 "
I need to get only "y3" and "y11" separately.
I’m a beginner and would appreciate any help.
>Solution :
import re
a = " practicing_regular_expressions_z1_test_y3_test_y11_1930 "
re.findall(r"y\d+", a) # ['y3', 'y11']
This is a bit quick and dirty, but it works. The \d+ means 1 or more digits so it will capture both.