This script illustrates a way to do it:
Names Default to Here( 1 );
dt = New Table( "Col Range Test Cases",
New Column( "A",
"Character",
"Nominal",
Values( { "CH1-2,CH17,CH6-8", "T7", "MR101-103", "P4-5", "U2", "AR6-7" } )
),
New Column( "B",
"Character",
"Nominal"
)
);
For Each Row(
// tokenize current string with comma delimiter
// Row() = 1;
range = Words( Column( dt, 1 )[], "," );
For( i = 1, i <= N Items( range ), i++,
// look for col range
result = Regex Match(
range[i],
"^(\w+?)(\d+)-(\d+)\b"
);
If( N Items( result ) == 0,
// regex failed, not a col range
If( i == 1,
// start string result
answer = range[i],
// add to string result
answer = Concat( answer, ", ", range[i] );
),
// regex succeeded, a col range
letters = result[2];
first = Num( result[3] );
last = Num( result[4] );
// append columns in the range
For( n = first, n <= last, n++,
col = Char( letters ) || Char( n );
If( i == 1 & n == first,
answer = col,
answer = Concat( answer, ", ", col );
);
);
);
);
// Row() = 1;
Column( dt, 2 )[] = answer;
);