简体   繁体   中英

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 ???

You need to use a non-default matching mode — line-aware — to make that RE simple:

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

Alternatively, you can put the option inside the RE itself:

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

The behaviour is exactly equivalent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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