<?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: Count the numeric passages in a string in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782230#M96546</link>
    <description>&lt;P&gt;Jarmo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great stuff!&amp;nbsp; Here's what I came up with in the end.&amp;nbsp; Label is the column containing the string I'm trying to perform surgery on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	New Column("Width", Character, "Nominal", Formula(Regex(:Label, "(\d+)X", "\1")), Set Selected);
	New Column("Length", Character, "Nominal", Formula(Regex(:Label, "X(\d+)", "\1")), Set Selected);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slán&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SpannerHead&lt;/P&gt;</description>
    <pubDate>Fri, 16 Aug 2024 15:34:22 GMT</pubDate>
    <dc:creator>SpannerHead</dc:creator>
    <dc:date>2024-08-16T15:34:22Z</dc:date>
    <item>
      <title>Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782174#M96536</link>
      <description>&lt;P&gt;This is probably a very specific one but I have a string contained in a JMP cell and I need to be able to isolate a specific passage of numeric characters in the string.&amp;nbsp; The string contains both characters and numbers and the sequence can be variable.&amp;nbsp; For example if I have the cell entry&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;aaa1b222c3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I want to zero in on the 222 passage, I considered a means to count the number of numeric passages as being 3 and then isolating the second of those.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I came up with a way to do this with Regex but it's too convolved to be worth posting.&amp;nbsp; I'm sure there's a more adaptive way of getting there.&amp;nbsp; All ideas appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slán&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SpannerHead&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 13:35:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782174#M96536</guid>
      <dc:creator>SpannerHead</dc:creator>
      <dc:date>2024-08-16T13:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782197#M96539</link>
      <description>&lt;P&gt;Could you provide more examples of the possible strings and the parts you wish to isolate? Also what do you want to do with those parts? Extract them? Remove them? Check if the exist?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 14:08:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782197#M96539</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-16T14:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782198#M96540</link>
      <description>&lt;P&gt;Jarmo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My overall goal is to create a new column that contains the numeric value as a cell input.&amp;nbsp; This derives from the fact that the original entry contains dimensional information and I'd like that to be automatically available in numeric form.&amp;nbsp; One of the numeric passages is a length, the other is a width.&amp;nbsp; There are other numbers included and I need a means to bypass those.&amp;nbsp; The actual string will look closer to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Val1b200X300&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which is a 200 long by 300 wide device and I need new columns containing cells generated reflecting those values.&amp;nbsp; The additional numeric characters are not consistent in length or placement which adds complexity to the task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slán&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SpannerHead&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 14:30:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782198#M96540</guid>
      <dc:creator>SpannerHead</dc:creator>
      <dc:date>2024-08-16T14:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782199#M96541</link>
      <description>&lt;P&gt;Are those always three characters long? Are they always the last two numbers? Are they always separated by "X"?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 14:32:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782199#M96541</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-16T14:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782202#M96542</link>
      <description>&lt;P&gt;Jarmo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Partial violation of Murphy's law.&amp;nbsp; Not always the same length, not always the last 2 numbers but always separated by an X.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slán&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SpannerHead&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 14:41:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782202#M96542</guid>
      <dc:creator>SpannerHead</dc:creator>
      <dc:date>2024-08-16T14:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782205#M96543</link>
      <description>&lt;P&gt;This might be enough or you might have to add few extra conditions (check that it is either at the start/end or there is letter before/after)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

str = "Val1b200X300abcc1";
r = Regex Match(str, "(\d+)X(\d+)");
Show(Num(r[2]), Num(r[3]));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Aug 2024 14:47:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782205#M96543</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-16T14:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782230#M96546</link>
      <description>&lt;P&gt;Jarmo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great stuff!&amp;nbsp; Here's what I came up with in the end.&amp;nbsp; Label is the column containing the string I'm trying to perform surgery on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	New Column("Width", Character, "Nominal", Formula(Regex(:Label, "(\d+)X", "\1")), Set Selected);
	New Column("Length", Character, "Nominal", Formula(Regex(:Label, "X(\d+)", "\1")), Set Selected);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slán&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SpannerHead&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 15:34:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782230#M96546</guid>
      <dc:creator>SpannerHead</dc:creator>
      <dc:date>2024-08-16T15:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782362#M96572</link>
      <description>&lt;P&gt;This depends on your data, but you might want to add a small addition to your regex patterns: add the check for other number on other side of X to avoid issues where you would just have something like "1Xa"&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

strs = {"A1X2", "A1Xa", "1X2", "a1X23", "aX2", "A1X2a"};

For Each({str}, strs,
	a1 = Regex(str, "(\d+)X", "\1");
	a2 = Regex(str, "X(\d+)", "\1");
	// vs
	b1 = Regex(str, "(\d+)X(\d+)", "\1");
	b2 = Regex(str, "(\d+)X(\d+)", "\2");
	
	Write("\!NCurrent string: ", str);
	Write("\!NFirst pattern matches: ", a1, " ", a2);
	Write("\!NSecond pattern matches: ", b1, " ", b2);
	Write("\!N");
);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Current string: A1X2
First pattern matches: 1 2
Second pattern matches: 1 2

Current string: A1Xa
First pattern matches: 1 .
Second pattern matches: . .

Current string: 1X2
First pattern matches: 1 2
Second pattern matches: 1 2

Current string: a1X23
First pattern matches: 1 23
Second pattern matches: 1 23

Current string: aX2
First pattern matches: . 2
Second pattern matches: . .

Current string: A1X2a
First pattern matches: 1 2
Second pattern matches: 1 2&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Aug 2024 05:30:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782362#M96572</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-17T05:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Count the numeric passages in a string</title>
      <link>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782385#M96580</link>
      <description>&lt;P&gt;Also my first understanding of the initial problem was to extract the longest sequence of numbers from a string, so here are few scripts for that (might be useful to someone).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Using Words() (similar idea could be used to extract non-numeric strings)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

str = "aaa1b222c3";

alphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
nums = Words(str, alphabets);

lengths = Transform Each({num}, nums, Output("Matrix"), Length(num));

l_idx = Loc Max(lengths);
longest_num_seq = nums[l_idx];

show(nums, longest_num_seq); //nums = {"1", "222", "3"}, longest_num_seq = "222";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Using While + Regex&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

str = "aaa1b222c3";

nums = {};
strcopy = str;
While(!IsMissing(match = Regex(strcopy, "\d+")),
	idx = Contains(strcopy, match);
	Insert Into(nums, match);
	Remove From(strcopy, idx, Length(match));
);

l_idx = Loc Max(lengths);
longest_num_seq = nums[l_idx];

show(nums, longest_num_seq); //nums = {"1", "222", "3"}, longest_num_seq = "222";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2024 15:05:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-the-numeric-passages-in-a-string/m-p/782385#M96580</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-17T15:05:34Z</dc:date>
    </item>
  </channel>
</rss>

