【问题标题】:I want to grep some text using regex. But it is not working我想使用正则表达式 grep 一些文本。但它不起作用
【发布时间】:2023-01-22 22:28:54
【问题描述】:

我必须 grep 一些文本,因为我已经在 python 脚本中编写了正则表达式格式来 grep 该文本。但这不是我想要的文本。

n="<directory>regression\UC400_019_TC15</directory>" Rep_str = re.findall(r"\b<directory>\w*</directory>\b",n) print(Rep_str)

我想为我制作的 re.findall 在“和 <\directory>”之间查找文本,其中“Rep_str”没有给出任何值。它正在打印空字符串。所以任何人都可以帮助我如何在“和 <\directory>”目录之间 grep 文本。

我试图 grep “和 <\directory>” 之间的文本。它给出空字符串的地方。所以我怎样才能在“和<\directory>”目录之间grep那个文本。

【问题讨论】:

    标签: python-3.x azure-pipeline-python-script-task


    【解决方案1】:

    试试这个正则表达式并使用.组(1)获取文本的方法:

    r'<directory>(.*?)</directory>'
    

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 1970-01-01
      • 2012-10-26
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多