python关键词提取_python-从日志文件中提取特定单词(不是关键字)

我正在尝试从下面的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值