<?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 pat match in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/pat-match/m-p/228224#M45277</link>
    <description>&lt;P&gt;Hi, I have a text string that I need to match, and I've been trying pat match() but don't have the grasp of it.&amp;nbsp;The text is a filename. I need to identify all files with a certain pattern:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"AB0007 25092019 0822.txt":&lt;/P&gt;&lt;P&gt;2 capital letters. "AB" actually always.&lt;/P&gt;&lt;P&gt;4 digits and a space&lt;/P&gt;&lt;P&gt;ddMMYYYY (or just 8 digits) and a space&lt;/P&gt;&lt;P&gt;4 digits&lt;/P&gt;&lt;P&gt;".txt"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying but failed with many versions, latest:&lt;/P&gt;&lt;P&gt;file="AB0007 25092019 0822.txt" // for testing; eventually it will be an item in a file list that I cycle through&lt;/P&gt;&lt;P&gt;pattern="AB"+"\d{4}"+"\s"+"\d{8}"+"\s"+"\d{4}";&lt;BR /&gt;pat match(file,pattern);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated!&lt;/P&gt;</description>
    <pubDate>Sun, 06 Oct 2019 00:10:53 GMT</pubDate>
    <dc:creator>peder</dc:creator>
    <dc:date>2019-10-06T00:10:53Z</dc:date>
    <item>
      <title>pat match</title>
      <link>https://community.jmp.com/t5/Discussions/pat-match/m-p/228224#M45277</link>
      <description>&lt;P&gt;Hi, I have a text string that I need to match, and I've been trying pat match() but don't have the grasp of it.&amp;nbsp;The text is a filename. I need to identify all files with a certain pattern:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"AB0007 25092019 0822.txt":&lt;/P&gt;&lt;P&gt;2 capital letters. "AB" actually always.&lt;/P&gt;&lt;P&gt;4 digits and a space&lt;/P&gt;&lt;P&gt;ddMMYYYY (or just 8 digits) and a space&lt;/P&gt;&lt;P&gt;4 digits&lt;/P&gt;&lt;P&gt;".txt"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying but failed with many versions, latest:&lt;/P&gt;&lt;P&gt;file="AB0007 25092019 0822.txt" // for testing; eventually it will be an item in a file list that I cycle through&lt;/P&gt;&lt;P&gt;pattern="AB"+"\d{4}"+"\s"+"\d{8}"+"\s"+"\d{4}";&lt;BR /&gt;pat match(file,pattern);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated!&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 00:10:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/pat-match/m-p/228224#M45277</guid>
      <dc:creator>peder</dc:creator>
      <dc:date>2019-10-06T00:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: pat match</title>
      <link>https://community.jmp.com/t5/Discussions/pat-match/m-p/228246#M45281</link>
      <description>&lt;P&gt;JSL has a &lt;EM&gt;regex&lt;/EM&gt; function that does traditional regex matches and a &lt;EM&gt;patmatch&lt;/EM&gt; function that can use snippets of regex if desired. The last example hints why you might want to use the &lt;EM&gt;patmatch&lt;/EM&gt; function.&amp;nbsp; Also notice the extra bit of either ^...$ or PatPos(0)...PatRPos(0) logic to make sure the entire filename was matched.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;file = "AB0007 25092019 0822.txt"; // for testing; eventually it will be an item in a file list that I cycle through

// decide if using (1) pure regex,
Show( Regex( file, "^AB\d{4}\s\d{8}\s\d{4}\.txt$" ) ); // "AB0007 25092019 0822.txt", or missing (.) if not matched

// or (2) pure pattern matching,
digit = Pat Any( "0123456789" );
pattern = Pat Pos( 0 ) + "AB" + Pat Repeat( digit, 4, 4 ) + " " + Pat Repeat( digit, 8, 8 ) + " " + Pat Repeat( digit, 4, 4 ) + ".txt" + Pat R Pos( 0 );
Show( Pat Match( file, pattern ) ); // rc is 1, it matches, 0 if fails to match

// or (3a) mix of both
pattern = Pat Pos( 0 ) + "AB" + Pat Regex( "\d{4}" ) + Pat Regex( "\s" ) + Pat Regex( "\d{8}" ) + Pat Regex( "\s" ) + Pat Regex( "\d{4}" ) + ".txt" + Pat R Pos( 0 );
Show( Pat Match( file, pattern ) ); // rc is 1, it matches, 0 if fails to match

// or collapse the mix (3b) a bit
pattern = Pat Pos( 0 ) + "AB" + Pat Regex( "\d{4}\s\d{8}\s\d{4}" ) + ".txt" + Pat R Pos( 0 );
Show( Pat Match( file, pattern ) ); // rc is 1, it matches, 0 if fails to match

// why you might choose (2) or (3a) -- you can capture substrings like the date part using the &amp;gt;&amp;gt; operator:
digit = Pat Any( "0123456789" );
pattern = Pat Pos( 0 ) + "AB" + Pat Repeat( digit, 4, 4 ) + " " + Pat Repeat( digit, 8, 8 ) &amp;gt;&amp;gt; datepart + " " + Pat Repeat( digit, 4, 4 ) + ".txt" + Pat R Pos( 0 );
Show( Pat Match( file, pattern ),informat(datepart,"ddmmyyyy") ); // rc is 1, Informat(datepart, "ddmmyyyy") = 25Sep2019;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Regex(file, "^AB\d{4}\s\d{8}\s\d{4}\.txt$") = "AB0007 25092019 0822.txt";&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Pat Match(file, pattern) = 1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Pat Match(file, pattern) = 1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Pat Match(file, pattern) = 1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Pat Match(file, pattern) = 1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Informat(datepart, "ddmmyyyy") = 25Sep2019;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JMP's regex is built on top of the pattern matching functions; neither one will be faster than the other. The &lt;EM&gt;PatRegex&lt;/EM&gt; function translates the regex into equivalent pattern matching functions so PatMatch will work.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 22:19:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/pat-match/m-p/228246#M45281</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-10-06T22:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: pat match</title>
      <link>https://community.jmp.com/t5/Discussions/pat-match/m-p/228439#M45319</link>
      <description>Not 1, not 2, but 5 solutions. Thank you so much!</description>
      <pubDate>Tue, 08 Oct 2019 10:08:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/pat-match/m-p/228439#M45319</guid>
      <dc:creator>peder</dc:creator>
      <dc:date>2019-10-08T10:08:08Z</dc:date>
    </item>
  </channel>
</rss>

