regex - Extract certain words from string using Tcl or REgExpr -
hi, trying extract engine string, has proven test (hold). in example bellow, output should proengine2.
engine1 {status fail reason checked depth 0 } engine2 {status fail reason checked depth 0 } proengine1 {status open reason checked depth 0 } **proengine2** {status **hold** reason checked depth 1 }
any idea how tcl or regular expression?
thanks, sasa
if want engine status hold
, try this:
regexp -- {([^\}[:blank:]]+?)\s*?\{status hold} $data - engine
your engine in $engine
variable.
([^\}[:blank:]]+?)
match non }
or blank characters (this engine name matched) , stored first submatch, engine
, provided next parts match, meaning spaces \s*?
, {status hold
.
if have multiple engines might try that:
set engines [regexp -all -inline -- {[^\}[:blank:]]+?(?=\s*?\{status hold)} $data]
where $engines
list of engines on hold
.
here, i'm using positive lookahead instead of capture groups because -all -inline
return list of matches , sub-matches. regex same, first pair of ()
removed , second part wrapped around (?= ... )
(which positive lookahead).
Comments
Post a Comment