Adding custom link with multiple matches in regex

Is there a way to have the regex for a custom link have a repetition that creates multiple links? For example a commit message could contain:

Case 123, 456: Fix some stuff

And then the regex 

/Case (?:(\d),?\s*)+/

Would capture both the 123 and 456. Correct? But I don't see how to make the replacement URL work here so that there are two links.

Neither the documentation for the web UI nor the REST API give much information about how the regular expressions work. They mention having capture groups in the regex, but nothing about repetition. Maybe the regex library being used doesn't support repeated captures.

If this is impossible (which it seems like it might be), is there a better way to handle this particular commit message so both 123 and 456 are links? Certainly this regex

/(\d+)/

or even this one

/(\d{3,})/

would work, but that seems excessive and could match things in commit messages where it maybe shouldn't.

1 answer

1 accepted

The Bitbucket Cloud linkers are based on Python regular expressions. Bitbucket Cloud uses re.finditer to scan the text in a given field and create a new link (where appropriate) for each match returned. What you're trying to do may be possible, but we don't have any tests or examples of this. Also, I couldn't make something work easily off hand. I'd suggest using something like http://pythex.org/ to test out the possibilities and see what you can get.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

2,006 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you