0

I am using Python to extract words from a text. I want to extract word that contain@ but not dot.

Regular expression should match following: @bob, cat@bob
Regular expression should not match: xyz@bob.com.

I tried following: (?:\w+)?@\w+(?!\.) - but it extracts @bob, cat@bob and xyz@bo.

Just to elaborate, if I have text "hi @bob and cat@bob my email is xyz@bob.com" I want to extract @bob and cat@bob only from this text. My regular expression above extracts part of xyz@bob.com (precisely it extracts xyz@bo). How can I avoid extracting xyz@bob.com completely.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

0

I was finally able to find a solution. The following expression worked for me: (?:\w+)?@\w+\b(?!.)