Complex Regex in Smart Value
Asked by Lucas Anschuetz:

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.


Answers:
author: Bill Sheboy
body: Hi [@Lucas Anschuetz](/t5/user/viewprofilepage/user-id/5385685) -- 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

comments: author: Lucas Anschuetz
body: 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


author: Bill Sheboy
body: 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?


author: Bill Sheboy
body: 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.


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

<br />

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!


author: Lucas Anschuetz
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

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](https://community.atlassian.com/t5/image/serverpage/image-id/296728i26D8E9D2290A66C1/image-dimensions/369x319?v=v2 "Automatition.png")

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

![ticket.png](https://community.atlassian.com/t5/image/serverpage/image-id/296731i541AA68F0EC8F1E4/image-size/large?v=v2&px=999 "ticket.png")

In the audit log, the run was successful.

![Audit-log.png](https://community.atlassian.com/t5/image/serverpage/image-id/296732i464779D68E27DBF7/image-size/large?v=v2&px=999 "Audit-log.png")

But the mail I receive, the result is missing:

<br />

![received-mail.png](https://community.atlassian.com/t5/image/serverpage/image-id/296733iA158F090ED127959/image-size/large?v=v2&px=999 "received-mail.png")

This is the result of my java regex test:

![regex-tester.png](https://community.atlassian.com/t5/image/serverpage/image-id/296734i6F1C671AFAE9A961/image-size/large?v=v2&px=999 "regex-tester.png")

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

Best regards