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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -