cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Regular expressions and multiple capture groups

Hi,

 

I have workflow with a text variable, which looks similar to that:

 

Settlement Date-2b

 

I'm interested in the first part, which is the "Settlement Date" as well as the number with the sign that is following the text. I have came up with the following regular expression:

 

^([a-zA-Z\s]*)([-+]?\d*)b?$

 

It has two capturing groups, that should capture the parts I want. When I run the regex with this value in a C# console application, I get 3 groups:

 

Settlement Date-2b

-2

Settlement Date

 

But when I run the same expression in "Regular expression" action in workflow, only one group is extracted, and it's the complete value of the input text:

 

issue_regex.gif

 

Is it possible to use use capturing groups in Nintex? If not, then only solution would be to split the operation into two actions - one extracting the first part, and second for the number with sign?

Labels: (2)
Reply
8 Replies
Workflow Hero

Re: Regular expressions and multiple capture groups

I am also having some issues with Nintex Regular Expressions. I am trying to test a URL to determine the folder depth after the library and while my regular expression works as expected in this tester .NET Regex Tester - Regex Storm , in Nintex it finds a match where it shouldn't. Just to share my test, I did.

Pattern: (https://sp.mycompany.com/Marketing/\w+/\w+/\w+/\S+/)

Input: (https://sp.mycompany.com/Marketing/Documents/1/2/3/ ) should match

(https://sp.mycompany.com/Marketing/Documents/1/2/) Should not match, but it does.

Maybe someone from Nintex can reply with some details about regular expressions.

Berney

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Regular expressions and multiple capture groups

you probably used extract operation in workflow action. that's I think correct since your expression explicitelly matches 'b' character.

you can reference matching (sub)groups and if you did that you could see they match exactly what you need

if you are not sure about position of your specific group, you can as well name it

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Regular expressions and multiple capture groups

reg. match/not match of: https://sp.mycompany.com/Marketing/Documents/1/2/

I think, your first \w+ matches 'Documents', your second \w+ matches '1' and your third \w+ matches '2'.

then your input string ends, so there is not match for at least one non-white space charcter aka \S+

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Regular expressions and multiple capture groups

Exactly, but for some reason I am getting a match.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Regular expressions and multiple capture groups

aah, I'm sorry, I uderstood it you want to match it.

if I test it on my env. it as well doesn't match.

but, one point to be sure. how do you want to treat parentheses in your strings?

I have tested myself everything without surrounding parentheses.

so, does your input string really contain a parentheses chars at the beginning and at the end of string?

do you want your regular expression to match these parentheses in input string or should they make up a subexpression in regex?

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Regular expressions and multiple capture groups

No my input string is the content item url. I am trying to create a regular expression to identify if a folder is created with more than 2 levels of depth. So I want the parenthesis to capture the string if there is a match. I didn't think this should match but it seems it is matching.

3-7-2016 10-38-11 AM.jpg

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Regular expressions and multiple capture groups

I affraid you just misinterpreted the result.

here is what docu says about 'replace text' operation:

since in this case your regex didn't match the pattern in input string, it didn't find anything what to replace - so you just see untouched input string.

you can check it with whatever input

reg. your target, if you just need to proof-check there are more then 2 levels (and do not need to know exact path) your better option might be 'check match' operation

Accept as Solution Reply
Workflow Hero

Re: Regular expressions and multiple capture groups

That answered my question. Thank you.

0 Kudos
Accept as Solution Reply