You are viewing limited content. For full access, please sign in.

Question

Question

regex token editor to pull folder name from middle of path

asked on March 18, 2017

Hi - I am trying to pull a single folder name from the middle of a full path variable.  For example, if:

Path = \RootFolder\SubLevel1\SubLevel2\SubLevel3\LastFolder

I can grab the first folder name or the last folder name, but I can't seem to successfully pull one of the "SubLevelX" folder names.  If anyone has a regex snippet that can pull the string from between "\" and "\" where I can specify the index number of "\", it would be much appreciated.

So, for example the string between the 3rd "\" and 4th "\" equals "SubLevel2".

Thanks, .... Steven.

0 0

Answer

SELECTED ANSWER
replied on March 22, 2017 Show version history

If the path you would like the folder from is from a token you can do what you want from token dialogue:

 

You just need to split on your folder separator (\ or / depending if it is web or file system) and then access the specific folder by using the index (either from the start or end).

 

 

This can also be done with the Token Calculator (which should really be renamed because it does a lot more than calculating, it allows advanced string multiplication).

1 0

Replies

replied on March 18, 2017 Show version history

You can use the pattern matching activity and extract each folder into a multi-value token that you could then index on.

The regexp is   \\?(.+?)\\|(.+)

The 3rd folder value could be referenced as %(PatternMatching_folders#[3]#) ="SubLevel2"

 

Andrew

(edited as the first regexp I posted did not include the last folder name)

3 0
replied on March 23, 2017

Andrew and Lindsay, thank you both!  Each solution seems to work equally well.

I've marked the Token/Split approach as the answer, mostly because I think it is more straightforward for someone who is not an expert on regular expressions (like me!) to understand and adapt to other situations.

But again, thank you both for two excellent solutions.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.