how to write regular expression using proc in TCL to deal with following pattern?
I am new to TCL and seeking a help to deal with the following expression. I am getting the i/p string from the user to validate any of these strings below & no others in a line in CLI using procedure
{ GHI GII GJI GKI}
and another tricky one is to write regexp to match only the characters which begin with alphabet A & end with B, It also have 1 o开发者_开发技巧r more of either YO or OY in between using procedure. Thank you
If that's your input, then really there's no need to use regular expressions: just check that a supplied word is in that list:
set input { GHI GII GJI GKI}
foreach word {GJI GLI} {
if {$word in $input} {
puts "$word is in [list $input]"
} else {
puts "$word is not in [list $input]"
}
}
A regex that matches "begin with alphabet A & end with B, It also have 1 or more of either YO or OY in between":
set re {^A(?:YO|OY)+B$}
foreach word {AYOB AYOOYB AYYB} {
if {[regexp $re $word]} {
puts "$word matches"
} else {
puts "$word does not match"
}
}
If you mean "either (1 or more of YO) or (1 or more of OY), then the regex is
set re {^A(?:(?:YO)+|(?:OY)+)B$}
精彩评论