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

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 Leaders.
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 Leaders.
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
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 5, 2023

Hi @Jason Barber,

Try this instead:

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

Will it work?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events