I want to use a regex to test a string in a macro #if.
I can't find a string method that will test a regex.
#if($labelName.match('.*'))<a href="/label/$spaceKey/$label">$label</a>#end
Hi @Hugh Kelley
Could not test it, but java gives the Matcher Class. Can you try with this?
#set($regex = ".*")#set($matcher = $regex.matcher($labelName))#if($matcher.matches())<a href="/label/$spaceKey/$label">$label</a>#end
Regards, Dominic
@Dominic Lagger , thank you for the hint. I had tried something similar initially but couldn't get the .matches() method to work. When I saw your suggestion, I dug a little deeper and realized that I wasn't getting the .matches() method because my variable was of class com.atlassian.confluence.labels.Label, not a Java String.
Once I added a .getName() method, I got a String and things worked as hoped.
#foreach ( $labelling in $page.getLabellings() ) #set( $label = $labelling.getLabel().getName()) #if( $label.matches($paramFeaturedLabels) ) <a href="/label/$spaceKey/$label">$label</a> #end#end
It looks like you're new here. Sign in or register to get started.