【发布时间】:2019-06-25 12:54:07
【问题描述】:
我正在尝试从以下 sample.txt 中提取几个单词(如预期输出所示)并将它们放入一个列表中。我在提取正确的字段时遇到了困难。我已经尝试过我的方法,但它不适用于大多数情况。我更喜欢使用 python 来做这件事,但对其他语言开放。非常感谢任何指向其他方法的指针。
sample.log
//*********************************************************************************
// update section
//*********************************************************************************
for (i=0; i< models; i = i+1) begin:modelgen
model_ip model_inst
(
.model_powerdown(model_powerdown),
.mcg(model_powerdown),
.lambda(_lambda[i])
);
assign fnl_verifier_lock = (tx_ready & rx_ready) ? &verifier_lock :1'b0;
native_my_ip native_my_inst
(
.tx_analogreset(tx_analogreset),
//.unused_tx_parallel_data({1536{1'b0}})
);
// END Section I :
//*********************************************************************************
resync
#(
.INIT_VALUE (1)
) inst_reset_sync
(
.clk (tx_coreclkin),
.reset (!tx_ready), // tx_digitalreset from reset
.d (1'b0),
.q (srst_tx_common )
);
预期输出
model_ip
native_my_ip
resync
我的尝试
import re
input_file = open("sample.log", "r")
result = []
for line in input_file:
# need a more generic match condition to extract expected results
match_instantiation = re.match(r'\s(.*) ([a-zA-Z_0-9]+) ([a-zA-Z_0-9]+)_inst (.*)', line)
if match_instantiation:
print match_instantiation.group(1)
result.append(match_instantiation.group(1))
else:
continue
【问题讨论】:
-
为什么在您的预期输出中是
resync而不是INIT_VALUE? -
我实际上是在寻找名字(在verilog中通常称为模块)。 resync 是一个模块名称。 INIT_VALUE 是一个参数,我不感兴趣。
-
匹配你需要的东西不会很漂亮,因为你的实例名称没有使用一致的格式。例如。你有 xxxx_inst 和 inst_xxxx。参数使这更加复杂。我建议你使用这个工具regex101.com 直到你得到你需要的东西。
-
@user2532296,您能否提供更多有关您如何获得预期输出的详细信息?就像您在特定关键字之后需要一个关键字?或者您需要在关键字等之前使用它?