The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Regex to extract number from summary not working

Jason Barber
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 4, 2023

I am attempting to extract a 6 digit number from the summary when certain text are present, my rule is successful but the regex is not entering into the field. 

edit issue expression:

{{issue.summary.match(/\d{6}/gm)}}

String example:

COMPANY SO # 123456

I am expecting "123456" to populate my custom field however it remains empty. on regedex101 the statement works correctly. 

What am I missing?

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
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 Champions.
October 7, 2023

Hi @Jason Barber -- Welcome to the Atlassian Community!

Two things to consider when using the match() function in automation rules...

First, the documentation describes the "underlying implementation is based on Java's Pattern class and uses Matcher.find() to find matches".  However it does not indicate what actually is (or is not) supported for regular expressions.  I recommend using the simplest expression that can possibly work, and always test to confirm the results.  Especially for any edge-cases.

Next, the match() function for rules returns only one match, and appears to treat line breaks as points to stop searching.  (Please see my above paragraph...)

The work-around is to always split on newlines first before attempting matches.  This will potentially result in a list of responses, and so ensure you handle that.  For your expression, try adding .split("\n") before the match() call.

Kind regards,
Bill

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 Champions.
November 4, 2023

Hi @Jason Barber 

Just following up to check if this answered your question.  If so, please consider marking this one as "answered".  That will help others with a similar need find solutions faster.  If not, please let the community know what help you need with the rule changes.

Thanks!

0 votes
Kseniia Trushnikova
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 Champions.
October 5, 2023

Hi @Jason Barber,

Try this instead:

{{issue.summary.match("([0-9]{6})")}}

Will it work?

TAGS
AUG Leaders

Atlassian Community Events