Start Free
SonarQube Community Build | Project administration | Setting analysis scope | Defining matching patterns

Defining matching patterns

On this page

Defining matching patterns for files

To define path-matching patterns, you can use the following wildcards:

  • *   matches zero or more characters (not including the directory delimiter, /).
  • **   matches zero or more directory segments within the path.
  • ?   matches a single character (not including the directory delimiter, /).

A file path definition is either relative to the sonar.projectBaseDir property (which is by default the directory from which the analysis was started; for more information, see Analysis parameters) or absolute. 

The table below shows path-matching pattern examples.

Matching patternDefinition
**/*.css<anyDirectory>/<anyFileName>.css
**/*Bean.java

<anyDirectory>/<anyString>Bean.java

Example: org/sonar.api/MyBean.java

**/*Bean?.java

<anyDirectory>/<anyString>Bean<singleCharacter>.java

Example: org/sonar.api/MyBean1.java

org/sonar/*org/sonar/<anyFile>
org/sonar/**
or
org/sonar/**/* 

org/sonar/<anyDirectory>/<anyFile>

Example: org/sonar/api/test/Bean.java

Defining matching patterns for coding rules

To define matching patterns for coding rules, use the following syntax:

<ruleRepository>:<searchString>

Where:

  • ruleRepository: is the identifier of the rule repository
    Examples: SonarQube java (identifier: java) or Security SonarAnalyzer PHP (identifier: phpsecurity), etc.
    You can use the wildcard pattern * (any string) to define the rule repository.
  • searchString: is any search string present in the rule key or in the rule name

The matching pattern means that any rule:

  • of the specified repository 
  • whose name or key contains the specified search string 

is a match.

Rule-matching pattern examples
Rule-matching patternDescription
css:S4655Rule ID s4655 in the repository css.
*:S4655Rule ID s4655 in any repository.
*All rules.
Identifying the repository, name, and key of a rule
  1. In the top navigation bar, select Rules.
  2. Use the filter on the left to search for a rule. The search results are displayed in the right panel.
  3. In the search results, click the rule you want to view. The rule opens and you can see the rule parameters. 

Was this page helpful?

© 2008-2025 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARQUBE, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License