Forums

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

Automation Using RegEX

Guy Slade July 12, 2024

What I am trying to do is grab the labels from an issue and then use regex to look for a pattern and if it is there assign the sting to a variable. As you can see below I am using a Restful call to grab an issue. I have:

parentLabels = {{webhookResponse.body.fields.labels}}

filterByRegEx = {{parentLabels.match("PI-[0-9]+-[0-9]+")}}

and as you can see below I write the values of these two vars out to the log. 

The parentLabels looks good but there is nothing in filterByRegEx. I know I have a string in parentLabels as I can successfully substring out what I am looking for when I hardcode the start and end. ( I am looking for "PI-3-24")

What dumb newbie mistake have I made?

 

Screenshot 2024-07-12 at 3.10.33 PM.png Screenshot 2024-07-12 at 3.04.55 PM.png

 

1 answer

1 accepted

1 vote
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 12, 2024 edited

Hi @Guy Slade -- Welcome to the Atlassian Community!

I see two things to adjust in your rule:

First, a created variable is plain text, and when the labels are added, by default the list flattens out to a comma-and-space separated values list.  To feed them into match(), they must be split back apart with split(", ") into a list.

Next, I believe the match() expression will need a group for this case.

Putting those together:

{{parentLabels.split(", ").match("(PI-[0-9]+-[0-9]+)")}}

Kind regards,
Bill

Guy Slade July 13, 2024

Thanks yet again Bill! That worked a treat. In case anyone else is going down this path, the last part to this was the advanced update that was required. What worked for me was the following:
{
  "update": {
    "labels": [
      {"add": "{{PITargetLabel}}" }
    ]
  }
}

Where PITargetLabel was my variable that is set using Bill's code above.

 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events