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

Question

Question

Position of a character in a string and Pattern Matching

asked on June 5, 2018

Hi All

I need to save files to folders based on UserName. 

File name is structured as UserName-scanned-timestamp. For Example file name may look like “jsmith-scanned-094315.pdf”.

How can I extract UserName out of file name given Username varies in length. 

One thought is to first find the position of the “-“.   Then select the string up to that length ( minus one to avoid getting “-“ ).

I am using Workflow and hoping to get this accomplished by using Pattern Matching.

Any suggestion on how to pattern matching and to select string up to a certain length?

Thanks

 

0 0

Answer

SELECTED ANSWER
replied on June 5, 2018

Hi Naveed,

 

There are a few ways that you can write the pattern to pick up what you're looking for. I was able to use (\w+)- to get the username from that string. This pattern says to grab any word characters before the '-'. You will want to test this pattern with a few different usernames/documents, since some discrepancies in the username (like if there's spaces or punctuation) will not be picked up by this pattern. We also have a good help file on using regular expression with Workflow that you can always refer to.

 

Hope this helps!

0 0

Replies

replied on June 15, 2018

Naveed,

 

I would use this pattern (\w+)\D.+  

\w+ gets all word characters

\D gets non-digit character (usually symbols and the like)

.+ says get everything afterward regardless of what type of character it is.

Putting the \w+ in parentheses like this (\w+) says that is all you want returned from the pattern. 

Here is what it looks like setting up a new token in Pattern Matching.

 

 

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

Sign in to reply to this post.