Is it possible to match over multiple lines using a regex?

Alex Bass October 13, 2022

Hi,

I'm trying to create a regular expression that I can use to remove email signatures from issues created from emails. I have something that works quite well in Notepad++ but it won't work in a replaceAll() function in a Jira automation over the description field.

One of the problems seems to be that replaceAll() (and also match()) doesn't seem to be able to match linebreaks. 

In addition, I have not been able to successfully use '^' or '$' to match line beginnings or endings.

So, my questions are:

1. Can somebody give me working example of a replaceAll() statement that uses '^', '$' and especially '\n'?

2. Is it somehow possible to make the dot greedy so that it consumes newline characters?

Thanks in advance,

Alex

2 answers

1 accepted

5 votes
Answer accepted
Yvan Martin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 17, 2022

Hi Alex,

Developer from Atlassian here.

Currently the regex expressions in Automation are using Java pattern matching. So when trying out expressions is best to use one that you can select the Flavour of Java e.g. https://regex101.com/?flavor=java&flags=g. The reason ^ and $ aren't working is by default multiline is being turned off (you can simulate that in that regex link). So you need to use the manual way of turning it on which is putting (?m) at the start of the regex.


Similar with using dot matcher on new lines, you'll need to use specify (?s) to force the regex into that mode. 

Example of using replaceAll to remove part of an email address from the issue description: 
Screen Shot 2022-10-17 at 6.35.14 pm.png


Hope that helps, you can also get in touch with support if you require further help with your rule.

Cheers.

Alex Bass October 17, 2022

Thank you, Yvan. That was the info I needed. I managed to get my regex to work.

0 votes
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 13, 2022

@Alex Bass -

Welcome to the community.  Have you looked at this following page dealing with automation - text operation - https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/

Hope this helps.

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Infrastructure Applications Team

Viasat Inc.

Alex Bass October 16, 2022

Thanks for your answer.

Yes, I have looked at the docs. 

And no, it hasn't helpled.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events