Tuesday, 15 April 2014

regex - Understanding tcl glob regexp? -



regex - Understanding tcl glob regexp? -

set d(aa1) 1 set d(aa2) 1 set d(aa3) 1 set d(aa4) 1 set d(aa5) 1 set d(aa6) 1 set d(aa7) 1 set d(aa8) 1 set d(aa9) 1 set d(aa10) 1 set d(aa11) 1 set regexp "a*\[1-9\]" set res [array names d -glob $regexp] puts "res = $res"

in case result are:

res = aa11 aa6 aa2 aa7 aa3 aa8 aa4 aa9 aa5 aa1

but when changed regexp a*\[1-9\] a*\[1-10\], results become:

res = aa11 aa10 aa1

you have error in character class.

[1-10] not mean digit 1 10 it means 1-1, character ranging 1 1 (i.e., 1), or 0. explains output. to express digit 1 10, utilize this: (?:10?|[2-9]) (as 1 of several ways it. therefore regex becomes a*(?:10?|[2-9]) note if engine not allow non-capturing group, need remove ?:, for: a*(?:10?|[2-9])

regex tcl

No comments:

Post a Comment