【问题标题】:Output the results of an RE输出 RE 的结果
【发布时间】:2014-07-25 07:37:07
【问题描述】:

我有以下代码:

import re

targetFile = open("test.txt").read()

print(re.search('(<\\/nesting_tag>)',targetFile))

我的想法是我返回 .例如。测试时的“测试”。我如何返回“测试”而不是 <_sre.sre_match>?

【问题讨论】:

  • 请给出正确的示例输入。
  • @JHarley 如果我的回答解决了您的问题,请确认。谢谢!

标签: python regex


【解决方案1】:

试试这个

print(re.search('(<\\/nesting_tag>)',targetFile).group())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多