Re: Regex help?



In article <3MidndnjAp51pyLfRVn-vA@xxxxxxxxxxx>, Smarta55 Chris wrote:

> Can someone help me find the last n folders in a path,
> or the last n OUs in a fully qualified Netware name... for an app object,
> etc?
>
> Example:
> \\server\volume\share\folder\folder\folder
> I want to grab just the last 2 folders (including or excluding the \s), but
> sometimes there
> are 3 folders after the share, like in the example, and sometimes there are
> more.
>
> Same for an app object in eDirectory
> .appobject.dept.biz.site.county.state.tree
> How to I grab just the .site.county.state.tree OUs?
> Sometimes there are 5 OUs after the app object, and sometimes more.
> I want, I think, to start at the end of the string, and grab everything
> after the 4th dot from the end, but
> don't have a clue how to code this.

Try using the split function:

my @folders = split(/\\/,$path);

Then @folders[-2..-1] contains the last two directories in the path.

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
.



Relevant Pages

  • Re: RegEx Help, Please? (match after n)
    ... or the last n OUs in a fully qualified Netware name... ... Same for an app object in eDirectory ... How to I grab just the .site.county.state.tree OUs? ...
    (comp.lang.perl.misc)
  • Regex help?
    ... Can someone help me find the last n folders in a path, ... or the last n OUs in a fully qualified Netware name... ... Same for an app object in eDirectory ... I want, I think, to start at the end of the string, and grab everything ...
    (comp.lang.perl)
  • RegEx Help, Please? (match after n)
    ... Can someone help me find the last n folders in a path, ... Same for an app object in eDirectory ... I want, I think, to "start at the end of the string, and grab everything ... anything mult times, followed by another literal dot, followed, etc... ...
    (comp.lang.perl.misc)
  • Re: RegEx Help, Please? (match after n)
    ... > I want to grab just the last 2 folders (including or excluding the ... perldoc -f reverse ... sub last_n_path_components { ...
    (comp.lang.perl.misc)
  • Re: Printing a list of files in a folder
    ... using Grab, but this is slow and cumbersome. ... setting a list of all the folders at once and getting it printed? ... where path/to/folder is the path to the folder you like to print. ...
    (comp.sys.mac.apps)