search

Home  >  Q&A  >  body text

Python regular expression to extract part of string content

1

2

<code>样本:user<user@test.com>

如何提取其中的 user@test.com 部分?</code>

Ask, how to optimally implement regular expression in Python?

typechotypecho2849 days ago832

reply all(2)I'll reply

  • 天蓬老师

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

    1

    2

    3

    4

    <code>import re

     

    str = 'user<user@test.com>'

    print re.search('<(.+)>', str).group(1)</code>

    reply
    0
  • 伊谢尔伦

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

    1

    2

    3

    4

    5

    <code># coding: utf8

    import re

    string = 'user<user@test.com>'

    print re.findall(r'<([^>]+)', string)

    </code>

    reply
    0
  • Cancelreply