两个字符串之间的python正则表达式匹配

时间:2016-07-24 18:24:00

标签: python regex pattern-matching

我有以下字符串:

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(。*))介于" @(posedge"和" | - >"。我试过的正则表达式是:

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

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

1 个答案:

答案 0 :(得分:1)

我会使用像

这样的东西
(?<=@\(posedge).*?(\!\(\$isunknown\(.*?\)\)).*?\|->

Regular expression visualization

Debuggex Demo

带有re.DOTALL标记的

,以便您的.表达式包含换行符。