gpt4 book ai didi

python 正则表达式在两个字符串之间进行匹配

转载 作者:太空宇宙 更新时间:2023-11-03 16:20:13 25 4
gpt4 key购买 nike

我有以下字符串:

property some_property_name;
@(posedge some_clock) disable iff (some_other_signal)
signalA && signalB || !($isunknown(some_other_signal)) &&
|-> !($isunknown(should_not_match_this))
endproperty

more_random_code

property some_other_property_name;
@(posedge some_clock) disable iff (some_other_signal)
signalA && signalB || \*!($isunknown(dont_match_if_commented_out))*\ &&
more_random_stuff ||
random_stuff
|-> some_other_expression
endproperty

property next_property_name;
@(posedge some_clock) disable iff (some_other_signal)
signalA && signalB || !($isunknown(some_other_signal)) &&
|-> some_other_expression && expressions_etc
endproperty

我想匹配 !($isunknown(.*)) 之间的“@(thoughtge”和“|->”。我尝试的正则表达式是:

(?<=@\(posedge ) ([^*]!\(\$isunknown\(.*\)[^*]) (?=(.*\n.*)*\|->)

但它与任何内容都不匹配,我不明白为什么。

最佳答案

我会使用类似的东西

(?<=@\(posedge).*?(\!\(\$isunknown\(.*?\)\)).*?\|->

Regular expression visualization

Debuggex Demo

re.DOTALL标记以便您的 . 表达式包含换行符。

关于python 正则表达式在两个字符串之间进行匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38555310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com