我有一串
set text {show log
===============================================================================
Event Log
===============================================================================
Description : Default System Log
Log contents [size=500 next event=7 (not wrapped)]
6 2020/05/22 12:36:05.81 UTC CRITICAL: IOM #2001 Base IOM
"IOM:1>some text here routes "
5 2020/05/22 12:36:05.52 UTC CRITICAL: IOM #2001 Base IOM
"IOM:2>some other text routes "
4 2020/05/22 12:36:05.10 UTC MINOR: abc #2001 some text here also 222 def "
3 2020/05/22 12:36:05.09 UTC WARNING: abc #2011 some text here 111 ghj"
1 2020/05/22 12:35:47.60 UTC INDETERMINATE: ghe #2010 a,b, c="7" "
}
我想在tcl中使用regexp提取以“ IOM:”开头的第一行
IOM:1>some text here routes
但是实施无法正常工作,有人可以在这里提供帮助吗?
regexp -nocase -lineanchor -- {^\s*(IOM:)\s*\s*(.*?)routes$} $line match tag value
您可以使用
See the Tcl demo
细节
(?n)
- newline sensitive mode ON so that.
could not match line breaks ( see Tcl regex docs: If newline-sensitive matching is specified, . and bracket expressions using ^ will never match the newline character (so that matches will never cross newlines unless the RE explicitly arranges it) and^
and$
will match the empty string after and before a newline respectively, in addition to matching at beginning and end of string respectively)^
- start of a line"IOM:
-"IOM:
string.*
- the rest of the line to its end.