Skip to main content
Nintex Community Menu Bar

Regular Expression: Get all after a backslash

  • January 14, 2020
  • 4 replies
  • 263 views

kelliganp
Forum|alt.badge.img+10

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-corpdoej" for a corporate user and "i:0#.w|mydomain-corpdoej" 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.

 

\(.*)

6145iD035B3F9C84A8CDF.png

 

Can anyone correct my pattern?

 

Thanks and Regards,

Patrick

4 replies

Forum|alt.badge.img+12
  • Scholar
  • January 14, 2020

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

 

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


kelliganp
Forum|alt.badge.img+10
  • Author
  • Rookie
  • January 14, 2020

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?


Forum|alt.badge.img+9
  • January 15, 2020

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:

(?<=\).*$

 

kelliganp
Forum|alt.badge.img+10
  • Author
  • Rookie
  • January 15, 2020

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