How can i find a pattern in a string?

check = [‘paldvlaklnvbe6’, ‘exvadn2’, ‘exadvaple2’, ‘example1’, ‘bye’, ‘hi’]
for i in check:
if ‘exple’ in i:
print(i)
from the above array ‘check’, i want to isolate ‘example1’,‘exadvaple2’ .
how can i do it? how should we write to look for patterns in strings?
thankyou.

Regex is probably what you need here,…

2 Likes
import re

check = ['paldvlaklnvbe6', 'exvadn2', 'exadvaple2', 'example1', 'bye', 'hi']

for i in check:
  if re.match(r'exa.*ple', i) is not None:
    print(i)
3 Likes