<?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: Extract number adjacent to String in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513970#M74126</link>
    <description>&lt;P&gt;If for some reason there is a need to tackle the issue &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/21049"&gt;@ngambles&lt;/a&gt; mentioned, one fairly simple way would be to use Regex Match instead of Regex&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
a = "400HFA isa300";
b = "isa300 HFA400";
c = "400HFA300";
d = "400HF300";

rgx_pattern = "(\d*)(?:HFA)(\d*)";
show(Regex Match(a, rgx_pattern));
show(Regex Match(b, rgx_pattern));
show(Regex Match(c, rgx_pattern));
show(Regex Match(d, rgx_pattern));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regex Match will though require some extra checks as it returns a list of groups captured.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jun 2022 20:03:50 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2022-06-24T20:03:50Z</dc:date>
    <item>
      <title>Extract number adjacent to String</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513318#M74083</link>
      <description>&lt;P&gt;Hi, can anybody help me to extract numbers adjacent to strings?&lt;/P&gt;&lt;P&gt;I have column1 shown below, and expect to extract numbers adjacent to "HFA" (column2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following JSL, but could not get column2 that I expect&lt;/P&gt;&lt;P&gt;Num( Regex( :Column 1, "(\d\d\d)HFA | HFA(\d\d\d)", "\1" ) )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;column1&lt;/TD&gt;&lt;TD&gt;column2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;400HFA isa300&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;isa300 HFA400&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for considering the question.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 17:02:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513318#M74083</guid>
      <dc:creator>AprioriFish3134</dc:creator>
      <dc:date>2023-06-09T17:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number adjacent to String</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513418#M74088</link>
      <description>&lt;P&gt;Given the small example set, the following formula works:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Num( Regex( :column1, "(\d*)HFA(\d*)", "\1\2" ) )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This solution will run into problems if you have instances like "400HFA300".&amp;nbsp; It will return 400300.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 00:20:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513418#M74088</guid>
      <dc:creator>ngambles</dc:creator>
      <dc:date>2022-06-24T00:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number adjacent to String</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513927#M74123</link>
      <description>&lt;P&gt;Hi Ngambels,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help. It resolved the issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did try&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;"(\d*)HFA(\d*)"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but apparently I missed (I did not know I can and must use both \1 and \2)&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;"\1\2"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I learned new things from you and through this discussion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again, thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 18:57:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513927#M74123</guid>
      <dc:creator>AprioriFish3134</dc:creator>
      <dc:date>2022-06-24T18:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number adjacent to String</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513970#M74126</link>
      <description>&lt;P&gt;If for some reason there is a need to tackle the issue &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/21049"&gt;@ngambles&lt;/a&gt; mentioned, one fairly simple way would be to use Regex Match instead of Regex&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
a = "400HFA isa300";
b = "isa300 HFA400";
c = "400HFA300";
d = "400HF300";

rgx_pattern = "(\d*)(?:HFA)(\d*)";
show(Regex Match(a, rgx_pattern));
show(Regex Match(b, rgx_pattern));
show(Regex Match(c, rgx_pattern));
show(Regex Match(d, rgx_pattern));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regex Match will though require some extra checks as it returns a list of groups captured.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 20:03:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/513970#M74126</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-24T20:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number adjacent to String</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/514077#M74133</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/41443"&gt;@AprioriFish3134&lt;/a&gt;&amp;nbsp; for pointing out the original issue (no \2), and &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/21049"&gt;@ngambles&lt;/a&gt;&amp;nbsp; for a good solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need even more levels of nested parens, or the sequential parens in your example, just count the open-parens from left-to-right to discover the back reference number. The back reference for unused alternatives is an empty string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Regex( "abac", "(((a)|(b)|(c))(c))+", "1=\1 2=\2 3=\3 4=\4 5=\5 6=\6" )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;"1=ac 2=a 3=a 4= 5= 6=c"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing that might not be obvious: the back reference can also be used in the pattern. This could be useful for making sure a leading and trailing quotation mark or apostrophe are used consistently:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Write( Regex( 
	"before 'a \!"b\!" c' after", // before 'a "b" c' after
	"(\!"|')(.*?)\1", // ("|')(.*?)\1
	"\2" 
) )
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;a "b" c&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;(The \!" escape puts a quotation mark inside the strings; the comment shows the text of the string.) In this example, \1 group can match either " or ' and \2 matches all of the text up to another occurrence of \1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use some comments if you write regex like that! The next maintainer will appreciate it.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 02:53:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/514077#M74133</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-06-25T02:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number adjacent to String</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/514098#M74135</link>
      <description>&lt;P&gt;Good place to practice and test regex is &lt;A href="https://regex101.com/" target="_blank" rel="noopener"&gt;https://regex101.com/&lt;/A&gt; .&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1656140400727.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/43561iE3F7621F2EB11035/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1656140400727.png" alt="jthi_0-1656140400727.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Those comments with JMP escape characters removed were very helpful, I have to start adding those when I write more complicated regex patterns (&lt;LI-MESSAGE title="Regex issue with escaped characters" uid="79540" url="https://community.jmp.com/t5/Discussions/Regex-issue-with-escaped-characters/m-p/79540#U79540" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; )&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 07:06:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/514098#M74135</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-25T07:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number adjacent to String</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/514692#M74163</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for enriching the discussion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In fact I first learned about JMP's regex from your old article !&lt;BR /&gt;&lt;A href="https://community.jmp.com/t5/Uncharted/Regex/ba-p/21008" target="_blank"&gt;https://community.jmp.com/t5/Uncharted/Regex/ba-p/21008&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2022 22:32:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/514692#M74163</guid>
      <dc:creator>AprioriFish3134</dc:creator>
      <dc:date>2022-06-27T22:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number adjacent to String</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/514693#M74164</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your alternative solution to the issue, and also for the link on regex.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2022 22:34:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-number-adjacent-to-String/m-p/514693#M74164</guid>
      <dc:creator>AprioriFish3134</dc:creator>
      <dc:date>2022-06-27T22:34:13Z</dc:date>
    </item>
  </channel>
</rss>

