Home  >  Q&A  >  body text

Python regular expression to extract part of string content

样本:user<user@test.com>
如何提取其中的 user@test.com 部分?

Ask, how to optimally implement regular expression in Python?

typechotypecho2686 days ago704

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-06-12 09:29:14

    import re
    
    str = 'user<user@test.com>'
    print re.search('<(.+)>', str).group(1)

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-12 09:29:14

    # coding: utf8
    import re
    string = 'user<user@test.com>'
    print re.findall(r'<([^>]+)', string)
    

    reply
    0
  • Cancelreply