Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Complex Regex in Smart Value

Lucas Anschuetz December 13, 2023

Dear Community,

I try to use a complexe regex to parse an mail adress from a specific scheme of a ticket summary.

Which smart value is able to use the result of this regex as "send to" in the "send mail" component in an global automatition.
The expression was successfully tested in an regex tester.

(?<=Created.*?via.*?e-mail.*?received.*?from: .*? <)([-A-Za-z0-9!#$%&'*+=?^_`{|}~]+(?:\.[-A-Za-z0-9!#$%&'*+=?^_`{|}~]+)*@(?:[A-Za-z0-9](?:[-A-Za-z0-9]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[-A-Za-z0-9]*[A-Za-z0-9])?)

Thanks in advance for your support.

2 answers

1 accepted

1 vote
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2023

Hi @Lucas Anschuetz -- Welcome to the Atlassian Community!

As the documentation states, with my emphasis, the "underlying implementation is based on Java's Pattern class and uses Matcher.find() to find matches."  However, it does not state what is (and is not) supported by that implementation.

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--

My experience and several community posts indicate things which work in other tools / programming languages for different flavors of regular expressions do not work in automaton rules.

 

Something I note in your expression is it has multiple groups and automation rules appear to only support the first one, regardless if it is a capture or non-capture.

 

My recommendations:

  • First thing: document all of the test cases you want to try, and make it easy to test them. For example, create a CSV file with your test data and use issue import and a test project to exercise your rule with the Issue Created trigger.
  • Start with the simplest regular expression that can possibly work, with no edge cases handled
  • Test thoroughly writing results to the audit log to check intermediary values
  • Incrementally add to your expression, until you reach your target outcome

When you are done, please post which expression actually worked for you to benefit the community.  Thanks!

Kind regards,
Bill

Lucas Anschuetz December 13, 2023

Hi @[deleted],

Thanks for your fast reply.

My regex was in javascript flavor, so i created a new one matching to Java with only one group.

Several Java Regex testers I used where successfull.

The automatition runs without an error, but i get no result.

\[Created via e-mail received from: .+ <([^>]+)>\]

Do you maybe have another hint for me?

Thanks in advance

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2023

Would you please post an image of your complete rule, an image of the action using that expression, and an image of the audit log details showing the rule execution?

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2023

Thanks for that information, Lucas.  Please try to stick to one thread when posting.  That will help others looking at this thread in the future know if there are multiple ways to solve the problem.

Back to your question...

I noted that you are searching the Summary field but the text you want to search is in the Description field.  Which is correct?

I adjusted your expression to use a Description field, and added a split on newlines before the match and it worked for me:

{{issue.description.split("\n").match("\[Created via e-mail received from: .+ <([^>]+)>\]")}}

This version of match() does not handle the newlines, and so I often split on them to reduce the search complexity.  When keeping the newlines is desired, I will replace them with a token first (e.g. MYNEWLINE), perform the match, and then swap them back.

Lucas Anschuetz December 14, 2023

Sorry, I clicked the wrong button to answer.
My test was successful. I meant the issue description but used the wrong smart value.


Like you wrote, this smart value including the regex is correct:  

{{issue.description.split("\n").match("\[Created via e-mail received from: .+ <([^>]+)>\]")}}

 Thank you for your kind help and idea input!

Like Bill Sheboy likes this
0 votes
Lucas Anschuetz December 13, 2023

@Bill Sheboy 

This is the rule overview:

If ticket is opened -> Then send mail to. Smart value in mail subject.

Used smart value: {{issue.summary.match("\[Created via e-mail received from: .+ <([^>]+)>\]")}}

Automatition.png

I created an ticket with the part where the regex should match:

ticket.png

In the audit log, the run was successful. 

Audit-log.png

But the mail I receive, the result is missing:


received-mail.png

 

 

This is the result of my java regex test:

regex-tester.png

 

If I should provide further or more detailed information, just let me know. 

Best regards

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events