Xpath regular expressions nowrking with sonarQube 7.6

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

I am using sonarQube 7.6
want to evaluate regular expressions in SonarQube


Am trying to explore SonarQube7.6 community edition for xml code review.

As part of building custom rule to validate the xml, created a regular expression - matches(//*[local-name() = ‘set-payload’]/@doc:name, ‘[A-Z]’)

But when evaluating the xml, the sonarqube is throwing below error. Can you please help me if there is any way in sonarqube to achieve the above.

matches(//*[local-name() = ‘set-payload’]/@doc:name, ‘[A-Z]’)

I am getting the below error while executing sonar-scanner:

Caused by: javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: Could not find function: matches

at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:400)

at org.sonar.plugins.xml.checks.XPathCheck.getXPathExpression(XPathCheck.java:112)

… 46 common frames omitted

Thanks and Regards,

Hi Kilani,

I’m guessing matches came with XPath 2.0. Our XPath rules only support 1.0.


Hi Ann,

Thanks for reply.As per my understanding and knowledge xpath 1.0 does not support regular expressions.So If I want to use regex in SonarQuve to validate xpath using regex how can I achieve?

Thanks and Regards,

Hi Kilani,

For some languages you have the option of creating a custom rules plugin and writing rules in Java. For others, you just have to make do with XPath 1.0.