Skip to main content
 首页 » 编程设计

Python 发出的 grep 正则表达式,匹配此模式

2025年05月04日23davidwang456

我不知道如何通过我通过 Python 发出的 grep 命令来匹配这个模式。

我想匹配一个形式为

的字符串

foo.bar([包括换行符、空格、制表符的任何内容]) 。

我正在尝试:

regex = " foo.bar(.*) " 
bashCommand = "grep"+" -r -h"+regex+baseDir 
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE) 
requires = process.communicate()[0] 

但是我无法匹配这个字符串

dojo.require("abc.def" 
 
 
    ); 

请您参考如下方法:

Grep 逐行工作,所以 "."实际上不匹配换行符。你可能会发现 this answer有帮助。