<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Converting  A Range of Alphanumeric Characters Into A List (X1-3 to X1,X2,X3) in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59225#M32536</link>
    <description>&lt;P&gt;A more efficient function for multiple results is &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Regex Match()&lt;/STRONG&gt;&lt;/FONT&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );

// test case
original = "CH002-033";

result = Regex Match(
	original,
	"^(\w+?)(\d+)-(\d+)\b"
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Note a slight change to first capturing group because "+" is greedy.)&lt;/P&gt;
&lt;P&gt;In this case, you get all the back references in a list form:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;{"CH002-033", "CH", "002", "033"}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jun 2018 19:07:11 GMT</pubDate>
    <dc:creator>Mark_Bailey</dc:creator>
    <dc:date>2018-06-04T19:07:11Z</dc:date>
    <item>
      <title>Converting  A Range of Alphanumeric Characters Into A List (X1-3 to X1,X2,X3)</title>
      <link>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59206#M32533</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to convert a range of alphanumeric characters into a list.&amp;nbsp;I'm pretty new to JSL and I'm not sure exactly how to go about doing this. This is what I would like to achieve:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Orginal: CH1-3&lt;/P&gt;&lt;P&gt;Return: CH1,CH2,CH3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The character prefix does not always contain two characters (Could be CH1-3 or X5-8 for example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that if I had a range of just two numbers, like CH1-2, &amp;nbsp;I could use the following script to get what I want:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Regex("CH1-2", "([A-Z]+)([0-9]+)(-)([0-9]+)", "\1\2,\1\4", GLOBALREPLACE);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which returns CH1,CH2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I have no idea how to do this for ranges with more than two numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 14:43:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59206#M32533</guid>
      <dc:creator>Stepper</dc:creator>
      <dc:date>2018-06-04T14:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Converting  A Range of Alphanumeric Characters Into A List (X1-3 to X1,X2,X3)</title>
      <link>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59207#M32534</link>
      <description>&lt;P&gt;This almost certainly isn't the most efficient or cleanest solution, but should do the trick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;list = {}; // new blank list
letters = Regex("CH13-18", "([A-Z]+)([0-9]+)(-)([0-9]+)", "\1");
From = Num(Regex("CH13-18", "([A-Z]+)([0-9]+)(-)([0-9]+)", "\2"););
To = Num(Regex("CH13-18", "([A-Z]+)([0-9]+)(-)([0-9]+)", "\4"););
For( x = From, x &amp;lt;= To, x++,
	string = Char(letters) || Char(x);
	Insert Into (list, string);
);
print(list);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Jun 2018 15:07:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59207#M32534</guid>
      <dc:creator>david707</dc:creator>
      <dc:date>2018-06-04T15:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting  A Range of Alphanumeric Characters Into A List (X1-3 to X1,X2,X3)</title>
      <link>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59225#M32536</link>
      <description>&lt;P&gt;A more efficient function for multiple results is &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Regex Match()&lt;/STRONG&gt;&lt;/FONT&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );

// test case
original = "CH002-033";

result = Regex Match(
	original,
	"^(\w+?)(\d+)-(\d+)\b"
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Note a slight change to first capturing group because "+" is greedy.)&lt;/P&gt;
&lt;P&gt;In this case, you get all the back references in a list form:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;{"CH002-033", "CH", "002", "033"}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 19:07:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59225#M32536</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2018-06-04T19:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Converting  A Range of Alphanumeric Characters Into A List (X1-3 to X1,X2,X3)</title>
      <link>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59233#M32541</link>
      <description>&lt;P&gt;Crude version that handles numbers that are greater than 9&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ch_split = function({ch_string}, {default local},
	first_num = regex(ch_string, "([0-9])");
	num_loc   = contains(ch_string, first_num);
	prefix    = substr(ch_string, 1, num_loc - 1);
	num_list  = words(substr(ch_string, num_loc), "-");
	start     = num(num_list[1]);
	end       = num(num_list[2]);

	ch_list = {};
	k = 0;
	for (i = start, i &amp;lt;= end, i++,
		k++;
		ch_list[k] = prefix || char(i);
	);
	ch_list
);

a1 = "ABC20-29";
ch_split(a1);

a2 = "CH1-2";
ch_split(a2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Jun 2018 15:49:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59233#M32541</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-06-04T15:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting  A Range of Alphanumeric Characters Into A List (X1-3 to X1,X2,X3)</title>
      <link>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59366#M32575</link>
      <description>&lt;P&gt;Thanks for your response! It's very helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to incoperate it with what I'm trying to do, but I'm having some difficulties. Perhaps you could lend me your assistance again?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm dealing with a data table like the one below, where I have multiple columns filled with data. I'm trying to replace the ranged values wherever they occur&lt;/P&gt;&lt;P&gt;Orginal:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CH1-2,CH17,CH6-8&lt;/TD&gt;&lt;TD&gt;MR101-103&lt;/TD&gt;&lt;TD&gt;U2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;T7&lt;/TD&gt;&lt;TD&gt;P4-5&lt;/TD&gt;&lt;TD&gt;AR6-7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Desired:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CH1,CH2,CH17,CH6,CH7,CH8&lt;/TD&gt;&lt;TD&gt;MR101,MR102,MR103&lt;/TD&gt;&lt;TD&gt;U2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;T7&lt;/TD&gt;&lt;TD&gt;P4,P5&lt;/TD&gt;&lt;TD&gt;AR6,AR7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I've come up with so far to try to replace the ranged values that appear in column A, but it isn't working.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;for (i=1, i&amp;lt;=nrows(dt), i++,

	A_List=words(column(dt, "A")[i], ",");
	
	letters = Regex(A_List, "([A-Z]+)([0-9]+)(-)([0-9]+)", "\1");
	From = Num(Regex(A_List, "([A-Z]+)([0-9]+)(-)([0-9]+)", "\2"););
	To = Num(Regex(A_List, "([A-Z]+)([0-9]+)(-)([0-9]+)", "\4"););
	For( x = From, x &amp;lt;= To, x++,
		string = Char(letters) || Char(x);
		Insert Into (A_List, string);
		);
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I appreciate your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jun 2018 15:52:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59366#M32575</guid>
      <dc:creator>Stepper</dc:creator>
      <dc:date>2018-06-05T15:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Converting  A Range of Alphanumeric Characters Into A List (X1-3 to X1,X2,X3)</title>
      <link>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59367#M32576</link>
      <description>&lt;P&gt;This script illustrates a way to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;= 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 &amp;lt;= last, n++,
				col = Char( letters ) || Char( n );
				If( i == 1 &amp;amp; n == first,
					answer = col,
					answer = Concat( answer, ", ", col );
				);
			);
		);
	);
	// Row() = 1;
	Column( dt, 2 )[] = answer;
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jun 2018 18:30:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Converting-A-Range-of-Alphanumeric-Characters-Into-A-List-X1-3/m-p/59367#M32576</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2018-06-05T18:30:17Z</dc:date>
    </item>
  </channel>
</rss>

