<?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: Regex on files in a directory in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58750#M32445</link>
    <description>&lt;P&gt;I have always found regular expressions frustrating, so I avoid them as much as possible :).&amp;nbsp; I could definitely be wrong, but I don't think they are mean to be applied across all items in a list.&amp;nbsp; Easiest solution would probably be to&amp;nbsp;loop through your files and throw out any that don't start with "dat." using something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;for(i=1, i &amp;lt;= N Items(files), i++,
	If(Substr(files[i],1,3)=="dat", //if first 3 letters of file name are "dat"
		open(dir||files[i])
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 May 2018 05:08:53 GMT</pubDate>
    <dc:creator>cwillden</dc:creator>
    <dc:date>2018-05-31T05:08:53Z</dc:date>
    <item>
      <title>Regex on files in a directory</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58725#M32432</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to generate a script that goes opens a file based on a regex expression (file starts with "dat"). My code is listed below and it does not appear to be working. Is there something special that needs to be done when using regex on a list?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dir = pick directory();&lt;BR /&gt;files = files in directory(dir);&lt;/P&gt;&lt;P&gt;datafile = regex(files, "(^dat.*)","\1");&lt;BR /&gt;open(dir||datafile);&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 20:22:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58725#M32432</guid>
      <dc:creator>tarkan_bih</dc:creator>
      <dc:date>2018-05-30T20:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Regex on files in a directory</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58750#M32445</link>
      <description>&lt;P&gt;I have always found regular expressions frustrating, so I avoid them as much as possible :).&amp;nbsp; I could definitely be wrong, but I don't think they are mean to be applied across all items in a list.&amp;nbsp; Easiest solution would probably be to&amp;nbsp;loop through your files and throw out any that don't start with "dat." using something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;for(i=1, i &amp;lt;= N Items(files), i++,
	If(Substr(files[i],1,3)=="dat", //if first 3 letters of file name are "dat"
		open(dir||files[i])
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 05:08:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58750#M32445</guid>
      <dc:creator>cwillden</dc:creator>
      <dc:date>2018-05-31T05:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Regex on files in a directory</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58780#M32454</link>
      <description>&lt;P&gt;Here is one way to implement &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8582"&gt;@cwillden&lt;/a&gt;'s solution with regex():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here( 1 );
dir = pick directory();
files = files in directory(dir);

for(i=1, i &amp;lt;= N Items(files), i++,
	If(!Is missing(regex(files[i],"^dat.*")), //if first 3 letters of file name are "dat"
		open(dir||files[i])
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 11:51:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58780#M32454</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2018-05-31T11:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Regex on files in a directory</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58783#M32457</link>
      <description>&lt;P&gt;Adding to the previous solutions, you probably want to work with the data tables after importing them with the Open() function. I would capture the data table references in another list. I will use the second solution as an example but obviously the same thing would work with the first solution as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );
dir = Pick Directory();
files = Files in Directory( dir );
data files = List();

For( i = 1, i &amp;lt;= N Items( files ), i++,
	If( !Is Missing( Regex( files[i], "^dat.*" ) ),
		ref = Open(dir||files[i]);
		Insert Into( data files, ref );
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 12:44:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58783#M32457</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2018-05-31T12:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Regex on files in a directory</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58872#M32466</link>
      <description>&lt;P&gt;If this case is as simple as stated (all target file names&amp;nbsp;begin with "dat") then either method works and both are easy to use. (One method to find a matching filename is based on character functions and the other method is based on regular expressions.)&amp;nbsp;If, in fact, the case is not simple or becomes more complex over time, the first approach might become more difficult or even impossible. That case is where regex would be a superior approach.&lt;/P&gt;
&lt;P&gt;(Note that JMP also defines 'patterns' of text with a full compliment of functions to make patterns and use patterns.)&lt;/P&gt;
&lt;P&gt;I don't think that&amp;nbsp;regular expressions are&amp;nbsp;frustrating. The syntax of regex&amp;nbsp;is simple enough.&amp;nbsp;I think that using regex or&amp;nbsp;any similar&amp;nbsp;method to find target patterns in real-world text is frustrating. But that is because of the mess in the unstructured data rather than the tool. If you must analyze text, then knowledge and skill with regex is valuable.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 15:47:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-on-files-in-a-directory/m-p/58872#M32466</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2018-05-31T15:47:41Z</dc:date>
    </item>
  </channel>
</rss>

