regex - Whole words in python regular expression -
how find whole words using regular expressions in python? use beautiful soup , re library parse document. in soup need find contents after word 'e-mail'. try
for sublink in link.findall(text = re.compile("[e-mail:0-9a-za-z]")): print sublink.encode('utf-8')
but not work.
here working example word extraction via regular expressions:
import re text = "first line\n" + \ "second line\n" + \ "important line! e-mail:mail@domain.de, phone:991\n" + \ "another important line! e-mail:tom@gmail.com, phone:001\n" + \ "another line" print text emails = re.findall("e-mail:([\w@.-]+)", text) print "found email(s): " + ', '.join(emails)
output:
found email(s): mail@domain.de, tom@gmail.com
not sure if that's looking for.
edit: characters 0-9a-za-z
can written \w
. , yes, added .
, -
. put them [\w@.-]
if there more possible characters.
Comments
Post a Comment