可以用?P<name>的方法给正则匹配的部分命名。

例:要将<字母,数字>的部分命名为test

x = "abc <haha,123> test @@"
pattern = "(?P<test>\<\w+,\d+\>)"
m = re.search(pattern, x)
r = m.group("test")
print r

输出:
<haha,123>

相关文章:

  • 2021-11-17
  • 2021-06-03
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
猜你喜欢
  • 2022-12-23
  • 2021-12-18
  • 2021-08-19
  • 2021-12-18
  • 2021-06-30
  • 2021-08-14
  • 2022-12-23
相关资源
相似解决方案