<?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: can I use Contains() within Match() in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/43788#M25303</link>
    <description>This solved my problem. Totally forgot about associative arrays. Thanks a lot!</description>
    <pubDate>Wed, 30 Aug 2017 13:08:11 GMT</pubDate>
    <dc:creator>vkessler</dc:creator>
    <dc:date>2017-08-30T13:08:11Z</dc:date>
    <item>
      <title>can I use Contains() within Match()</title>
      <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20056#M18289</link>
      <description>&lt;P&gt;I need to search a character column to look to see if each rows value contains specific strings and then create an indicator name/group accordingly in the new column (it will be searching for ~14 specific strings).&amp;nbsp; I'm pretty sure nested IF() would be pretty slow...&amp;nbsp; I have used Match() in the past when I want to match exact strings, but can I use wildcards?&lt;/P&gt;
&lt;P&gt;I tried * and % but to no avail:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Match( :columnOfInterest,
     "*StringA*", "String A",
     "*StringB*", "String B",
     "" )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I then tried to use Contains() within the Match() and still no luck:&lt;/P&gt;
&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Match( :columnOfInterest,
     Contains(:columnOfInterest, "StringA"), "String A",
     Contains(:columnOfInterest, "StringB"), "String B",
     "" )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I see that Contains returns a numeric so I also tried adding &amp;gt; comparison and even wrapping in NUM():&lt;/P&gt;
&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Match( :columnOfInterest,
     Contains(:columnOfInterest, "StringA") &amp;gt; 0, "String A",
     Contains(:columnOfInterest, "StringB") &amp;gt; 0, "String B",
     "" )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="font-size: 13.3333px;"&gt;and&lt;/P&gt;
&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Match( :columnOfInterest,
     Num(Contains(:columnOfInterest, "StringA")) &amp;gt; 0, "String A",
     Num(Contains(:columnOfInterest, "StringB")) &amp;gt; 0, "String B",
     "" )&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P style="font-size: 13.3333px;"&gt;any help is greatly appreciated.&amp;nbsp; thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:15:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20056#M18289</guid>
      <dc:creator>jmpbeginner</dc:creator>
      <dc:date>2017-08-30T13:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: can I use Contains() within Match()</title>
      <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20057#M18290</link>
      <description>&lt;P&gt;&lt;A href="https://community.jmp.com/people/JMPbeginner" target="_blank"&gt;JMPbeginner&lt;/A&gt;​&lt;/P&gt;
&lt;P&gt;I would avoid conditional statements altogether. A better solution is to use Regex. For example, suppose your search terms were car models, "Accord", "Civic", etc, a Regex statement can be written that says -&lt;STRONG&gt;"Match ANY of the terms"&lt;/STRONG&gt;. In JSL, a column formula for this would look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Regex( :columnOfInterest,  "(Accord|Civic|Corolla|Dakota|Integra|Maxima|Ranger|S10)" );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attached is a simple demo file of this. Regex is extremely powerful at string pattern matching. There are numerous options for matching partial words, word stems, etc. Hope this help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-PBZ&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 14:13:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20057#M18290</guid>
      <dc:creator>Phil_Brown</dc:creator>
      <dc:date>2018-06-14T14:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: can I use Contains() within Match()</title>
      <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20058#M18291</link>
      <description>&lt;P&gt;Regex is the way to do, here is a very simple example that will do the multiple matching you want.&amp;nbsp; Just expand it with the strings you are looking for.&amp;nbsp; It will return the match it finds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
 
test="Answer is ABC";
TheMatch = regex(test,"(ABC|DEF|GHI)","\1");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:16:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20058#M18291</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2017-08-30T13:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: can I use Contains() within Match()</title>
      <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20059#M18292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks PBZ and Jim, Regex() works great and now I have a new tool to use while scripting! much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Aug 2016 17:25:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20059#M18292</guid>
      <dc:creator>jmpbeginner</dc:creator>
      <dc:date>2016-08-23T17:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: can I use Contains() within Match()</title>
      <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20060#M18293</link>
      <description>&lt;P&gt;this all makes sense, now I'm going to try to complicate things...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;regex(test,"(ABC|DEF|GHI)","\1")
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;can I return a different string than what is matched?&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;if "ABC" is found, return "group1",&lt;/LI&gt;
&lt;LI&gt;if "DEF" is found, return "group2", etc&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or is that not possible with regex?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:16:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20060#M18293</guid>
      <dc:creator>jmpbeginner</dc:creator>
      <dc:date>2017-08-30T13:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: can I use Contains() within Match()</title>
      <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20061#M18294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Note that the "\1" doesn't actually make a difference since we only have 1 pattern. If there were multiple parentheses, then indeed one could have "\1" or "\n" where n is &amp;lt;= number of patterns. See JMP online doc ==&amp;gt; &lt;A href="http://www.jmp.com/support/help/Regular_Expressions.shtml" title="http://www.jmp.com/support/help/Regular_Expressions.shtml"&gt;Regular Expressions&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Aug 2016 21:41:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20061#M18294</guid>
      <dc:creator>Phil_Brown</dc:creator>
      <dc:date>2016-08-23T21:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: can I use Contains() within Match()</title>
      <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20062#M18295</link>
      <description>&lt;P&gt;&lt;A href="https://kvoqx44227.lithium.com/people/JMPbeginner" target="_blank"&gt;JMPbeginner&lt;/A&gt;​&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="12586_Screen Shot 2016-08-23 at 7.34.19 PM.png" style="width: 512px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/3617iD42605EB106042E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="12586_Screen Shot 2016-08-23 at 7.34.19 PM.png" alt="12586_Screen Shot 2016-08-23 at 7.34.19 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use an Associative Array to store a lookup table of the strings you want to map to different strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, above :searchTerms and :mappedTerms are the keys and values of such an associative array. In the code below, this array is assigned to the variable "lookup". In the final formula for the RESULTS-mapped column, you'll see that every match found by the Regex serves as the argument for the lookup array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g. Take row 1 in the above table. The found result is "Integra" and the mapped result is lookup["Accord"] which is "GroupA"&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;fmlaExpr = Expr(
     If( Row() == 1,
          lookUp = Associative Array( :searchTerms, :mappedTerms, Empty() );
          vals = :searchTerms &amp;lt;&amp;lt; get values;
          doThis = Expr(
               lookUp[Regex( :ColumnOfInterest, Char( "(" || Concat Items( vals, "|" ) || ")" ) )]
          );
          doThis;
        ,
          doThis
     )
);
Eval( Eval Expr( :RESULTS-mapped &amp;lt;&amp;lt; set formula( Expr( Parse( Char( NameExpr(fmlaExpr)) ) ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attached is the complete example table.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:18:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/20062#M18295</guid>
      <dc:creator>Phil_Brown</dc:creator>
      <dc:date>2017-08-30T13:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: can I use Contains() within Match()</title>
      <link>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/43788#M25303</link>
      <description>This solved my problem. Totally forgot about associative arrays. Thanks a lot!</description>
      <pubDate>Wed, 30 Aug 2017 13:08:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/can-I-use-Contains-within-Match/m-p/43788#M25303</guid>
      <dc:creator>vkessler</dc:creator>
      <dc:date>2017-08-30T13:08:11Z</dc:date>
    </item>
  </channel>
</rss>

