I think both of those regexes would have the same exact matching. The parentheses would capture a match into a backreference which wouldn’t be usable. If you wanted to match a literal ( or ), I think you’d need to escape them with backslashes.
Regardless, if you’re just trying to check if the URI starts wtih /cjj or /(cjj), you could use a string pattern instead. This would be significantly more efficient than a regex.
switch -glob [HTTP::path] {
"/(cjj)*" { pool cjj01-BRO }
"/cjj*" { pool cjj01-WSE }
}
Normally you could use a capturing group defined by the expression in the parentheses to capture the matched characters. Here’s an example:
regexp -inline {test([0-9]} “test321654654” original match
$original would be set to the original string of test321654654 and $match would be set to 321654654. See the TCL wiki page for regexp for details: http://www.tcl.tk/man/tcl8.4/TclCmd/regexp.htm
In your example, matches_regex doesn’t support saving the matches. And it’s much more efficient to use a string function to do the HTTP path checking anyhow.
Another engineer use this and I need to maintanian this irule ,but confused by ()
So you mean we use a capturing group by the expression in () to capture the matched characters
for example ([0-9]) test321654654
so 321654654 will be captured to $match
and if I use () in matches_regex ,because matches_regex doesn’t support saving the matches,so it is useless.it will only work like a normal character without ()