regex仅以value1开头,而没有value1 \ nvalue2

问题描述 投票:0回答:1

正则表达式中的新增功能,尝试在服务器上捕获字符串仅以value1开头的文件,但是如果文件中有value1和下一个字符串value2,则不将其添加到输出中>]

keyword = re.findall(r'^process.args=spring.*?xml(?!process.script=true)', line,re.S)

有任何建议吗?

需要这样的输出:

xxxx xxx xxx xxx
process.args=spring.xxxx.xml
process.script=true
xxxx xxx xxx xxx\n```

output after regex : None

and 

```xx xx xxx xxx xxx
xxxx xxx xxx xxx
process.args=spring.xxxx.xml
xxxx xxx xxx xxx```

output after regex : process.args=spring.xxxx.xml

正则表达式中的新增功能,尝试在服务器上捕获字符串仅以value1开头的文件,但是如果文件中有value1和下一个字符串value2,则不将其添加到输出关键字= re.findall(r'^ process.args =中。 ..

python regex regex-negation regex-group
1个回答
0
投票

在您的模式中,在xml(?!process之后立即使用负前瞻xml。但是因为它在字符串的末尾,所以可以在\r?\nprocess

© www.soinside.com 2019 - 2024. All rights reserved.