匹配具有特定文本并以方括号内的_P结尾的行
我有几行文本,例如,下面有两行:
a[15].s16.l = (xy[11].s16.l > (50/*QUE-const:VECTWord->CC_Init_P*/))
xyz = Exh[(16/*QUE-const:VECT_dir->_num_P*/) & 0x0FU ];*/))
我想匹配具有“QUE-const”并以方括号 [] 中的“_P”结尾的行。
我写了以下正则表达式:
[.*QUE-const.*_P.*
但它匹配两行,而应该只匹配第二行。
请检查并纠正我哪里出错了。
回答
使用您显示的样本,您能否尝试以下操作。
[.*?QUE-const.*?_P.*?]
这是上述正则表达式的在线演示
说明:为以上添加详细说明。
[.*?QUE-const.*?_P.*?]
##Matching [ and till QUE-const then match till _P(with non-greedy quantifier) till first occurrence of ] here.