<?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 to pull file from path with JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28675#M19116</link>
    <description>&lt;P&gt;You can use the JSL function Words() to separate a path into its component part, and then take just the last piece. Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;full_path = {"C:\dir1\dir2\dir3\dir4\file.xlsx"}; i = 1; // setup&lt;/P&gt;&lt;P&gt;full_path[i] = "C:\dir1\dir2\dir3\dir4\file.xlsx";&lt;/P&gt;&lt;P&gt;filename = Words(full_path[i], "\"); // separate the path based on the backslash as a delimiter - returns a list&lt;/P&gt;&lt;P&gt;filename = filename[N Items(filename)]; // get the last&amp;nbsp;string in the list&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*:&lt;/P&gt;&lt;P&gt;"file.xlsx"&lt;/P&gt;</description>
    <pubDate>Wed, 02 Nov 2016 21:54:22 GMT</pubDate>
    <dc:creator>Melanie_J_Drake</dc:creator>
    <dc:date>2016-11-02T21:54:22Z</dc:date>
    <item>
      <title>Regex to pull file from path with JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28674#M19115</link>
      <description>&lt;P&gt;I am sure this is a straightforward answer to this question, but if I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;full_path[i] = "C:\dir1\dir2\dir3\dir4\file.xlsx"&lt;/P&gt;&lt;P&gt;and I want to get just "file.xlsx" and the directory depth is variabile, i.e. maybe 2 directories maybe 5, how would I do it? &amp;nbsp;In Perl I would split the string into an array by the \ and grab the last part of the array, but not sure how to do this in JSL. &amp;nbsp;Any help would be appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 21:37:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28674#M19115</guid>
      <dc:creator>drblove</dc:creator>
      <dc:date>2016-11-02T21:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to pull file from path with JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28675#M19116</link>
      <description>&lt;P&gt;You can use the JSL function Words() to separate a path into its component part, and then take just the last piece. Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;full_path = {"C:\dir1\dir2\dir3\dir4\file.xlsx"}; i = 1; // setup&lt;/P&gt;&lt;P&gt;full_path[i] = "C:\dir1\dir2\dir3\dir4\file.xlsx";&lt;/P&gt;&lt;P&gt;filename = Words(full_path[i], "\"); // separate the path based on the backslash as a delimiter - returns a list&lt;/P&gt;&lt;P&gt;filename = filename[N Items(filename)]; // get the last&amp;nbsp;string in the list&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*:&lt;/P&gt;&lt;P&gt;"file.xlsx"&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 21:54:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28675#M19116</guid>
      <dc:creator>Melanie_J_Drake</dc:creator>
      <dc:date>2016-11-02T21:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to pull file from path with JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28676#M19117</link>
      <description>&lt;P&gt;Try the &lt;A title="JMP Online Documentation" href="http://www.jmp.com/support/help/13/List_Functions.shtml#2491421" target="_blank"&gt;Words() function&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;full_path = "C:\dir1\dir2\dir3\dir4\file.xlsx";

listofwords=words(full_path, "\");

filename=listofwords[nitems(listofwords)];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*:&lt;/P&gt;
&lt;P&gt;"file.xlsx"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 21:56:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28676#M19117</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2016-11-02T21:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to pull file from path with JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28677#M19118</link>
      <description>&lt;P&gt;Two examples of how it could be done:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;full_path = "C:\dir1\dir2\dir3\dir4\file.xlsx";

//Regex (fails if filename contains non-word characters)
file1 = Regex(full_path, "[\w.]+$"); 
// Split string
file2 = Reverse(Words(full_path, "\"))[1];

Show(file1, file2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Nov 2016 22:03:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28677#M19118</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2016-11-02T22:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to pull file from path with JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28678#M19119</link>
      <description>&lt;P&gt;word ( -1, full_path[i], "\" )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use negative values, in the word() function, so -1 gives the last word, using the delimiter of choice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 22:29:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/28678#M19119</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2016-11-02T22:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to pull file from path with JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/29012#M19247</link>
      <description>&lt;P&gt;This is a great solution, one line. &amp;nbsp;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 15:35:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-to-pull-file-from-path-with-JSL/m-p/29012#M19247</guid>
      <dc:creator>drblove</dc:creator>
      <dc:date>2016-11-09T15:35:07Z</dc:date>
    </item>
  </channel>
</rss>

