Hello Everyone,
Just seeking a favour to write a regular expression to match the following set of strings. I want to write an expression which matches all the following strings TCL
i) ( XYZ XZZ XVZ XWZ )
Clue : Starting string is X and Z ending string is same for all the pairs. Only the middle string is differs Y Z V W.
My trial: [regexp {^X([Y|Z|V|W]*)Z$}]
I want to write an another regexp which catches/matches only the following string wherever comes
ii) (XYZ)
My trial: [regexp {^X([Y]*)Z$}]
or simply regexp {^XYZ$}
Just want to make sure its a correct approach. Is there any other way available to optimize the regexp :)
i) 1st Question Tested
set to_Match_Str "XYZ XZZ XVZ XWZ"
foreach {wholeStr to_Match_Str} [regexp -all -inline {X[YZVW]Z} $to_Match_Str] {
puts "MATCH $to_Match_Str in the list"
}
It prints only XZZ XWZ from the list. Its leaves out XYZ & XVZ When I include the paranthesis [regexp -all -inline {X([YZVW])Z} $to_Match_Str]. It prints all the middle characters correctly Y Z V W