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

Question

Question

Question about Alternation in pattern matching

asked on November 18, 2020

Hello Everyone. I have been doing a bunch of Pattern matching recently and besides the fact that Worfklow pattern matching seems to have different behavior than Quickfield pattern matching, it has been tough. My question comes down to Alternation. The way I understand it to work and I have got it to work sometimes is that I can have multiple regex patterns separated by the pipe | and if one of them matches, it works. So to prove my point of how crazy this is, this is the situation I'm in now. This SHOULD work. 

I have 9 digits and the first regex is \d{9}. The second set is to account for an underscore after the first 2 digits. If I delete the second regex, the result field is perfect. 

If I only use the second regex, it also works. 

So both my regex work until I use the | and then I don't get a result. WHY??? It does not make sense to me. It should match either one right?!?!

Please help. Thank you. 

 

 

0 0

Answer

SELECTED ANSWER
replied on November 19, 2020

Your \d{9} is not a match group, so the expression finds it but does not extract it. The second part is not checked because the first found a value. To extract the value, it should be (\d{9}).

For the second part, \W will not match the underscore. \W is the equivalent of "not a-zA-Z_0-9".

(\d\d)_?(\d{7}) should handle both cases.

2 0
replied on November 19, 2020

Oh, I see. My capture groups... I was thinking I could treat it like 2 separate expressions. I see now that it was matching but I was missing a capture group so there were no results. 

Thank you Mituna, I was losing my mind on this and I just needed a second set of eyes on it. 

0 0

Replies

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

Sign in to reply to this post.