Guest User

Untitled

a guest
Jul 29th, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. re.findall failing for regex with grouping in Python
  2. pat = "[w]+[ ]*@[ ]*[w]+.[w]+"
  3. re.findall(pat, 'abc@cs.stansoft.edu.com .rtrt.. myacc@gmail.com ')
  4.  
  5. ['abc@cs.stansoft', 'myacc@gmail.com']
  6.  
  7. pat = "[w]+[ ]*@[ ]*[w]+(.[w]+)*"
  8. re.findall(pat, 'abc@cs.stansoft.edu.com .rtrt.. myacc@gmail.com ')
  9.  
  10. ['.com', '.com']
  11.  
  12. pat = "[w.]+ *@ *w+(?:.w+)*"
  13. re.findall(pat, 'abc@cs.stansoft.edu.com .rtrt.. myacc@gmail.com ')
  14.  
  15. pat = '([w.-]+)@([w.-]+)'
  16. re.findall(pat, 'abc@cs.stansoft.edu.com .rtrt.. myacc@gmail.com ')
  17.  
  18. [('abc', 'cs.stansoft.edu.com'), ('myacc', 'gmail.com')]
  19.  
  20. emails = 'abc@cs.stansoft.edu.com .rtrt.. myacc@gmail.com '
  21. pat = '([w.-]+)@([w.-]+)'
  22. re.sub(pat, r'1@live.com', emails)
  23.  
  24. 'abc@live.com .rtrt.. myacc@live.com '
  25.  
  26. pat = '[w.-]+@[w.-]+'
  27. re.findall(pat, 'abc@cs.stansoft.edu.com .rtrt.. myacc@gmail.com ')
  28.  
  29. ['abc@cs.stansoft.edu.com', 'myacc@gmail.com']
Add Comment
Please, Sign In to add comment