Having issue with back reference in TCL
问题 I have the following code: set a "10.20.30.40" regsub -all {.([0-9]+).([0-9]+).} $a {\2 \1} b I am trying to grep 2nd and 3rd octet of the IP address. Expected output: 20 30 Actual output: 20 04 0 What is my mistake here? 回答1: You need to set the variables for the match and captured groups, then you can access them. Here is an example: set a "10.20.30.40" set rest [regexp {[0-9]+\.([0-9]+)\.([0-9]+)\.[0-9]+} $a match submatch1 submatch2] puts $submatch1 puts $submatch2 Output of the demo 20