I have a range string either in the form of [Numeric1] or [Numeric1:Numeric2] Brackets are part of string as well.
I want to have one regular expression that will give me Start index and another regular expression to give me End Index regardless of the input string.
I have managed to do it, but I was just wondering if there are better ways of doing it. Here is how I did it
#[5]
set range_1 "\[5\]"
#[7:9]
set range_2 "\[7:9\]"
set reg_exp_for_start_index {\[([0-9]*)\]|\[([0-9]*):[0-9]*\]}
set reg_exp_for_end_index {\[([0-9]*)\]|\[[0-9]*:([0-9]*)\]}
set iStart1 [regsub $reg_exp_for_start_index $range_1 {\1\2}]
puts "Start index for Range 1: $iStart1"
set iEnd1 [regsub $reg_exp_for_end_index $range_1 {\1\2}]
puts "End index for Range 1: $iEnd1"
set iStart2 [regsub $reg_exp_for_start_index $range_2 {\1\2}]
puts "Start index for Range 2: $iStart2"
set iEnd2 [regsub $reg_exp_for_end_index $range_2 {\1\2}]
puts "End index for Range 2: $iEnd2"
I get the expected output which is
Start index for Range 1: 5
End index for Range 1: 5
Start index for Range 2: 7
End index for Range 2: 9
What I don't like is I used or (|) and I have to concatenate the strings as {\1\2}.