Custom Rule with regex

I see in the documentation that we could make xpath rules
but I don’t have the impression that we can make a regex, I saw that it has a field with Ant-style matching patterns, but I don’t know if it corresponds to a regex expression
in my case , I would like to check the syntax of the calendar name with a regex

 <Calendar name="**c_standard**" year="2019" publicHolidays="1" specificDays="0" firstInWeek="0"

In the Custom Rule form
Field Expression


Field FilePattern
nothing yet

I tried to add “match” in the xpath expression but it doesn’t work
Can you help me

  • SonarQube 8.4.2

I just tested

// Calendars / Calendar [fn: matches (@name, '^ [a-zA-Z0-9] * _ [a-zA-Z0-9] * $')] 

I have the error message

java.lang.IllegalStateException: Failed to compile XPath expression based on user-provided parameter [//Calendars/Calendar[fn:matches(@name,'^[a-zA-Z0-9]*_[a-zA-Z0-9]*$')]]

the doc that I followed
can you help me ?

hello !
no one has dealt with this type of case ?

Hello @Jerome_LEBAS,

Unfortunately, you won’t be able to write such a pattern with our XPath rule, as your rule is based on XPath 3.1 syntax.

The XML analyzer XPath rule we are providing is only able to process XPath 1.0 syntax. We tried in the past to provide support of XPath 2.x and 3.x, without success. See SONARXML-68 for further details.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.