<?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: Regular Expression with Workato Lookup Table in Workato Pros Discussion Board</title>
    <link>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6826#M2943</link>
    <description>&lt;P&gt;Thank you Gary.&lt;/P&gt;&lt;P&gt;I tried this out and worked. Quick question, I'm trying to map and update batch of 100+ records in this use case. With this method, is there a way I can map the batch record?&amp;nbsp; Or do I need to loop each record to with the Javascript action?&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jun 2024 15:48:46 GMT</pubDate>
    <dc:creator>hendrykurnia</dc:creator>
    <dc:date>2024-06-05T15:48:46Z</dc:date>
    <item>
      <title>Regular Expression with Workato Lookup Table</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6814#M2937</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I have a use case where I use regular expression to validate the input of postal code.&lt;/P&gt;&lt;P&gt;E.g.&amp;nbsp;Formula = &lt;STRONG&gt;"95000-2707".match?(/(^\d{5}$)|(^\d{5}-\d{4}$)/)&lt;/STRONG&gt; for matching the US postal codes.&lt;/P&gt;&lt;P&gt;However, this method won't work if the regular expression is stored in a lookup able.&lt;/P&gt;&lt;P&gt;E.g. "&lt;SPAN&gt;regular_expression" lookup table&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;country&lt;/TD&gt;&lt;TD width="50%"&gt;regex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;United States&lt;/TD&gt;&lt;TD width="50%"&gt;/(^\d{5}$)|(^\d{5}-\d{4}$)/&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Formula = &lt;STRONG&gt;"95000-2707".match?(lookup("regular_expression", "country": "United States")["regex"])&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have also tried the following formula but no luck.&lt;/P&gt;&lt;P&gt;-&amp;nbsp;&lt;STRONG&gt;"95000-2707".match?(lookup("regular_expression", "country": "United States")["regex"].to_s)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;- &lt;STRONG&gt;"95000-2707".match?(/lookup("regular_expression", "country": "United States")["regex"]/)&lt;/STRONG&gt; and "&lt;STRONG&gt;95000-2707".match?(/lookup("regular_expression", "country": "United States")["regex"].to_s/)&lt;/STRONG&gt; with the following lookup table&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;country&lt;/TD&gt;&lt;TD width="50%"&gt;regex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;United States&lt;/TD&gt;&lt;TD width="50%"&gt;(^\d{5}$)|(^\d{5}-\d{4}$)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 23:38:16 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6814#M2937</guid>
      <dc:creator>hendrykurnia</dc:creator>
      <dc:date>2024-06-04T23:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression with Workato Lookup Table</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6817#M2938</link>
      <description>&lt;P&gt;You &lt;EM&gt;would&lt;/EM&gt; be able to do this with the Ruby "send" method, something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;[postal_code].send("match", regex)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But alas, Workato doesn't support "send".&lt;/P&gt;&lt;P&gt;However, you can still do this with a JavaScript action.&lt;/P&gt;&lt;P&gt;Set it up like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="regex2.png" style="width: 999px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1327i93146DA2EDAA88A4/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="regex2.png" alt="regex2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And use this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;exports.main = async ( {term, inputRegex}) =&amp;gt; {

  var reg = new RegExp(inputRegex);
  result = reg.test(term);
  console.log(reg);
  return { result };
  
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 02:25:47 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6817#M2938</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2024-06-05T02:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression with Workato Lookup Table</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6826#M2943</link>
      <description>&lt;P&gt;Thank you Gary.&lt;/P&gt;&lt;P&gt;I tried this out and worked. Quick question, I'm trying to map and update batch of 100+ records in this use case. With this method, is there a way I can map the batch record?&amp;nbsp; Or do I need to loop each record to with the Javascript action?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 15:48:46 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6826#M2943</guid>
      <dc:creator>hendrykurnia</dc:creator>
      <dc:date>2024-06-05T15:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression with Workato Lookup Table</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6831#M2947</link>
      <description>&lt;P&gt;Glad this worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's possible to do this in batches.&amp;nbsp;Here's the updated code.&lt;/P&gt;&lt;P&gt;The postal_codes input is an array of postal codes and countries. You'll need to match this format from your source data.&lt;/P&gt;&lt;P&gt;The lookup_table input is the entire lookup table (use the "Get all entries from..." action)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="regex2_1.png" style="width: 999px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1332iD0BB05CF2B432168/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="regex2_1.png" alt="regex2_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And here's the updated code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;exports.main = async ( {postal_codes, lookup_table} ) =&amp;gt; {
  
  console.log(postal_codes);
  const lut = lookup_table;
  const response = [];
  
  postal_codes.forEach(function (i) {
    console.log(i);
    let pc = i.postal_code;
    let c = i.country;
    let match = lut.filter(function(l) {
      return l.entry.col1 == c;
    });
    let reg = new RegExp(match[0].entry.col2);
    let result = reg.test(pc);
    let resultObj = { 
      postal_code: pc, 
      country: c,
      regex: reg,
      result: result
    };
    response.push(resultObj);
  });
 
  console.log(response);
  return { response };
  
  }
 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI, there's no error handling in this, so if the lookup fails, the whole thing might crash. JavaScript is not my native tongue &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 16:49:03 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6831#M2947</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2024-06-05T16:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression with Workato Lookup Table</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6833#M2949</link>
      <description>&lt;P&gt;Thanks Gary.&lt;/P&gt;&lt;P&gt;I would like to share what I have found. Actually, removing the '/' at the beginning and end of the regex in formula syntax and lookup table works.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;country&lt;/TD&gt;&lt;TD width="50%"&gt;regex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;United States&lt;/TD&gt;&lt;TD width="50%"&gt;(^\d{5}$)|(^\d{5}-\d{4}$)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;STRONG&gt;"95000-2707".match?(lookup("regular_expression", "country": "United States")["regex"])&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Give it a shot&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 17:23:05 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6833#M2949</guid>
      <dc:creator>hendrykurnia</dc:creator>
      <dc:date>2024-06-05T17:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression with Workato Lookup Table</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6834#M2950</link>
      <description>&lt;P&gt;Well, that's a whole lot easier! You know, when I was working on the script, I also had to remove the '/' at the beginning and end to get it to work, but I didn't think to double back and check if that would work with Ruby! Glad it's all working now.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 17:26:30 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/regular-expression-with-workato-lookup-table/m-p/6834#M2950</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2024-06-05T17:26:30Z</dc:date>
    </item>
  </channel>
</rss>

