cancel
Showing results for 
Search instead for 
Did you mean: 
kelliganp
Nintex Newbie

Regular Expression: Get all after a backslash

Jump to solution

Hi Folks,

 

I am trying to use a regular expression to get everything after the "\" in an account name for the author of an item. Examples of an account name for my site are "i:0#.w|mydomain-corp\doej" for a corporate user and "i:0#.w|mydomain-corp\doej" for an external user. I can successfully do this with several extra actions and the fn-Remove() inline function but since the removed lengths for an internal and an external user are different, I thought regex might be a bit more elegant and not require me to use a Set a condition action. I tried the following pattern but it includes the backslash and I am a noob at regex.

 

\\(.*)

2020-01-14_13-29-01.png

 

Can anyone correct my pattern?

 

Thanks and Regards,

Patrick

Labels: (1)
0 Kudos
Reply
4 Replies
Automation Master
Automation Master

Re: Regular Expression: Get all after a backslash

Jump to solution

@kelliganp ....did you try using "Replace" option? 

 

Replace "i:0#.w|mydomain-corp\" with "leave the field empty".

0 Kudos
Reply
kelliganp
Nintex Newbie

Re: Regular Expression: Get all after a backslash

Jump to solution

Yes, as a matter of fact, I did make that work. I used the following patrtern...

(^.*?(?=\\)\\)

...that I had found in another post. This leaves me with only the userID if I leave the Replacement text input box empty. I have a working solution now but for acedemic's sake, I am wondering what is wrong with my original pattern. Any idea?

0 Kudos
Reply
mlauer
Nintex Newbie

Re: Regular Expression: Get all after a backslash

Jump to solution

Pattern \\(.*) matches a backslash followed by zero to unlimited number of characters. The capturing group () is not necessary, \\.* would do the same here.

 

Use positive lookbehind (?<=\\) to match only the characters after the backslash by extract function:

(?<=\\).*$

 

View solution in original post

0 Kudos
Reply
kelliganp
Nintex Newbie

Re: Regular Expression: Get all after a backslash

Jump to solution

Tha worked @mlauer. So the positve lookbehind is always (?<=\\) with positions 5 or in my case 5 and 6 due to the special of reserved character neededing to be escaped, being the character to look behind?

The extract function has the .*$ at the end. The regex site I am looking at reads:

.* matches any character (except for line terminators)...
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)...
$ asserts position at the end of a line...

 

I think I understand the first two (look for ANYthing else... and ...look at all of the rest) but help me understand the $. Why is that needed?

 

Thanks and Regards,

Patrick

0 Kudos
Reply