Is there a way to use REGEX in jira expressions using ScriptRunner Jira Cloud?

Anzar
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.
August 24, 2023

Hi,

I am trying to add a regular expression in the scripted validator in Jira Cloud for the text field with an email address.

I tried with

issue.customfield_10000 =~”^([])$”

But it is failing.

The error is:

Jira expression failed to parse: line 1, column 24: ., ?., [, ?.[, (, *, /, %, +, -, <, <=, >, >=, ==, !=, &&, ||, ??, ?, ; or EOF expected, = encountered.

I can use the native way but it doesn't allow me to add a custom error message.

3 answers

1 accepted

0 votes
Answer accepted
Anzar
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.
September 11, 2023

I found the answer myself:

issue.customfield_10000.match('^([])$')!=null

This worked like a charm.
You can validate any regex against a custom field during a transition.

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 25, 2023

Hi @Anzar

Could you provide a little bit more information on what you want the Regex to do and where are you setting the regex to do?

Thank you and Kind regards,
Ram

Anzar
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.
August 25, 2023

I want the regex to validate if the email field has the correct value.

for example: ramkum@..

is an incorrect form of email.

 

ramkumar@gmail.com

is a valid email.

Regards,

Anzar Khan

0 votes
Alisa Zamaraeva
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.
August 24, 2023

Hi @Anzar 

I can't tell if the regular expression is valid or not, but the error tells you that you should use "==" operator, not "=" since you compare two values.

 

Best regards,

Alisa

Anzar
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.
August 25, 2023

Hi Alisa,

I dont want to do an equal comparison, I want to compare a regular expression with a string.

Suggest an answer

Log in or Sign up to answer