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.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -