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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.