Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Regex is duplicating parts of a URL

Patrick Haley July 29, 2021

Hey everyone, 

I'm trying to create an automation that when a link to an external Jira issue is added to the comments, it pastes the link into a custom External URL field. I'm new to regex so to test it I'm just having Jira bot return a comment with the URL.

When I add the URL into a comment as a hyperlink, Jira bot returns the URL back twice. However, If I paste a non-hyperlinked URL into the comments, it works correctly.

2021-07-29_13-41-09.png

I'm not exactly sure what I'm missing when I try to insert {{issue.comment.last.body.match("(https:\/\/jira.test.com\/browse\/ABC-\d+)")}} into the comment. 

2021-07-29_13-46-46.png

Any help is greatly appreciated. 

1 answer

1 accepted

0 votes
Answer accepted
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.
July 29, 2021

Hi @Patrick Haley 

If you were to export that issue with the comment and look at the body, I expect you will see it includes something like this

[https://jira.test.com/browse/ABC-135|https://jira.test.com/browse/ABC-135|smart-link]

So the URL is in there twice and so needs to be parsed accordingly, such as using the Match to make it a list, and then returning only one entry.

Best regards,
Bill

Patrick Haley July 29, 2021

How do you make a list from the match and then return just that value?

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.
July 29, 2021

I can think of two ways to accomplish your goal:

  • no list: Modify the regex to account for that pipe symbol (so you only get one URL), and then strip off the extraneous characters with the replaceAll function
  • with list, and easier: Please note in your comment how Match added a comma between the values, so it should already be a list.  You can just grab one by adding .first after your Match call.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events