python - Check if part of string contains regex pattern -
i have list of strings. each string contains random text , sequence of numbers , letters may or may not match regex.
example string:
"bla bla bla 123-abc-456 bla bla blaaha"
123-abc-456
match regex.
i wish store matching sequences new list; sequence is, not bla bla bla.
how done? need break out sequence using regex somehow.
in case have 1 "sequence" per string interested in:
in [1]: import re in [2]: re.search(r'\d{3}-\d{3}-\d{3}', ..: "bla bla bla 123-abc-456 bla bla blaaha").group() out[2]: '123-abc-456'
just in for
loop , save results new list.
if want multiple matches, use re.findall
suggested above.