I would like to get only the sentences which match the regex pattern as output and avoid these NONE, how do i group the output which matches the pattern?
import re regex = re.compile('(.*)(?:India)') with open("D:/txt_res/abc.txt") as f: for line in f: result = regex.search(line) print(result)
The output which im getting is
None
None
None
<_sre.SRE_Match object; span=(0, 101), match='Email: abc.bitz@gmail.com >
None
None
None
<_sre.SRE_Match object; span=(0, 47), match='XYZ Engineer at ABC Organization, India'>
None
None
<_sre.SRE_Match object; span=(0, 32), match='Intern at S360, India'>
None
None
Aucun commentaire:
Enregistrer un commentaire