<?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 Extracting a number from a text field in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Extracting-a-number-from-a-text-field/m-p/351251#M60084</link>
    <description>&lt;P&gt;I have a column containing text notes entered by technicians. They enter the system usage hours, which I need to extract into it's own column. Fortunately, the data is pretty consistent, and so I have been able to pull the info out using Regex Match(), but selecting the last value is tripping me up.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Regex Match( :diagnosis, "(ys.+sage: ?)(\d{1,5})\n" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do I extract the System Usage hours from the text block effectively?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample text looks like this:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;UDI# 123456789123456789123456789456123&lt;/P&gt;&lt;P&gt;Device received, missing cover.&lt;/P&gt;&lt;P&gt;Major Reason For Service: xxxxxxxxxx&lt;/P&gt;&lt;P&gt;System usage: 2372&lt;BR /&gt;System PM due in: 7627&lt;BR /&gt;xxx usage: 120&lt;BR /&gt;yyy usage: 208&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jun 2023 23:25:05 GMT</pubDate>
    <dc:creator>robressler</dc:creator>
    <dc:date>2023-06-10T23:25:05Z</dc:date>
    <item>
      <title>Extracting a number from a text field</title>
      <link>https://community.jmp.com/t5/Discussions/Extracting-a-number-from-a-text-field/m-p/351251#M60084</link>
      <description>&lt;P&gt;I have a column containing text notes entered by technicians. They enter the system usage hours, which I need to extract into it's own column. Fortunately, the data is pretty consistent, and so I have been able to pull the info out using Regex Match(), but selecting the last value is tripping me up.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Regex Match( :diagnosis, "(ys.+sage: ?)(\d{1,5})\n" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do I extract the System Usage hours from the text block effectively?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample text looks like this:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;UDI# 123456789123456789123456789456123&lt;/P&gt;&lt;P&gt;Device received, missing cover.&lt;/P&gt;&lt;P&gt;Major Reason For Service: xxxxxxxxxx&lt;/P&gt;&lt;P&gt;System usage: 2372&lt;BR /&gt;System PM due in: 7627&lt;BR /&gt;xxx usage: 120&lt;BR /&gt;yyy usage: 208&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:25:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extracting-a-number-from-a-text-field/m-p/351251#M60084</guid>
      <dc:creator>robressler</dc:creator>
      <dc:date>2023-06-10T23:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting a number from a text field</title>
      <link>https://community.jmp.com/t5/Discussions/Extracting-a-number-from-a-text-field/m-p/351271#M60085</link>
      <description>&lt;P&gt;If the data is consistent enough you could do this without regex by using Substr with Contains (and Length)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
text ="UDI# 123456789123456789123456789456123

    Device received, missing cover.

    Major Reason For Service: xxxxxxxxxx

    System usage: 2372
    System PM due in: 7627
    xxx usage: 120
    yyy usage: 208";
  
stringToSearch = "System usage: ";
sysUsage = num(Substr(text, Contains(text, stringToSearch) + length(stringToSearch), 4));
show(sysUsage);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Edit1: Or by using Words and Word:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
text ="
UDI# 123456789123456789123456789456123

Device received, missing cover.

Major Reason For Service: xxxxxxxxxx

System usage: 2372
System PM due in: 7627
xxx usage: 120
yyy usage: 208";

list_of_rows = Words(text, "\!N");
Show(list_of_rows);
sysUsage = Word(3, list_of_rows[4]);
Show(sysUsage);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Edit2: &lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;And finally regex with same text:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
text ="
UDI# 123456789123456789123456789456123

Device received, missing cover.

Major Reason For Service: xxxxxxxxxx

System usage: 2372
System PM due in: 7627
xxx usage: 120
yyy usage: 208";

//note "\2"
matchRegex = Regex(text, "(System usage: )(\d{1,5})", "\2");
Show(matchRegex);

//note index of number
matchList = Regex Match(text,"(System usage: )(\d{1,5})");
Show(matchList);
Show(matchList[3]);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 21:31:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extracting-a-number-from-a-text-field/m-p/351271#M60085</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-01-20T21:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting a number from a text field</title>
      <link>https://community.jmp.com/t5/Discussions/Extracting-a-number-from-a-text-field/m-p/351273#M60086</link>
      <description>&lt;P&gt;Here is a solution that uses JSL functions to extract the System Usage&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Num( Word( 1, Substr( :Diagnosis, Contains( :Diagnosis, "System usage:" ) + 14 ), "\!n" ) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="systemusage.PNG" style="width: 566px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/29604iC83F6E598279830C/image-size/large?v=v2&amp;amp;px=999" role="button" title="systemusage.PNG" alt="systemusage.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I have attached the above data table&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 21:29:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extracting-a-number-from-a-text-field/m-p/351273#M60086</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-01-20T21:29:44Z</dc:date>
    </item>
  </channel>
</rss>

