简体   繁体   English

如何在TCL中使用regexp检索1(从M 1 COMPLD)此行?

[英]How to retrieve 1 (from M 1 COMPLD) this line using regexp in TCL?

set sample "act-user:IMLI:nmss:1::***;
imli 2013-10-21 15:13:54
M  1 COMPLD
;
IMLI 2013-10-21 15:13:54
;
>"

How to retrieve 1 (from M 1 COMPLD) this line using regexp in TCL ??? 如何在TCL中使用regexp检索1(从M 1 COMPLD)此行?

You need to use a non-default matching mode — line-aware — to make that RE simple: 您需要使用非默认匹配模式(可识别行)来简化RE:

regexp -line {^M\s+(\d+)\s+COMPLD$} $sample -> value
puts "value = $value"

Alternatively, you can put the option inside the RE itself: 或者,您可以将选项放在RE自身内部:

regexp {(?n)^M\s+(\d+)\s+COMPLD$} $sample -> value
puts "value = $value"

The behaviour is exactly equivalent. 该行为是完全等效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM