Using regex capture groups in velocity Edited

I´m setting up templates in JETI using velocity templates and HTLM, i´d like to use regex capture groups to retieve data from custom files. But I´m not quite sure how to invoke regex capture group in Velocity/Java, i´ve seen plenty of examples on how to replace text and verify matches but I have yet to find or figure this out. 

 

I can use this to retrive the customfiled data and present it to the user:

#set ($string =$!jetiFieldRenderer.renderCustomField($issue, "customfield_10238").toLowerCase())
$string

 

Here is what I think i need to do in JAVA but I´m not sure how to make velocity do it and present it.
Pattern pattern = Pattern.compile("\[(.*)\(.*\)\]"); 
Matcher matcher = pattern.matcher($string); 
matcher.group(1)

1 answer

@Anders Lantz, did you ever figure this out? This is also what I need to do, but it is not working, Maybe the correct classes are not exposed in the Velocity context for user macros?

Nah I had to resort to using "replaceAll" several times on the same custom field. 

For reference, here is one regex i used:

$!jetiFieldRenderer.renderCustomField($issue, "customfield_10515").replaceAll('(\[|\]| \(\w*-\d*\))','') 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Tuesday in Uncategorized

Friday fun: how many celebrates Midsummer holiday or is this a Swedish tradition only?

Any other country that celebrates Midsummer holiday (this friday 22 June)?  

44 views 3 1
Join discussion

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