Configuring Regex Rules
Published 17 September 2025
Defining and configuring rules with a regular expression is a relatively simple way to define coding standards in your organization.
Rules are defined as text files with various fields defined in each file using TOML format. It is limited in capability as a regex is a text pattern matching process, it has no awareness of the structure and semantics of the code being analyzed. As such it is best for simple patterns and checks.
- You can use the
rulesLocationparameter to direct Flyway. - If you want to add rules it is a matter of creating new files following the structure outlined below.
Configuration
For purposes of setting policy, all you need to do is change the severity file in each rule.
Regular expression rules format
When using regular expression rules for code review through check -code, the format of the TOML rules files is as follows:
| Field | Purpose | Type | Possible Values | Example |
|---|---|---|---|---|
| code | Rule Code | String | Anything | RX001 |
| dialects | Which dialect of SQL does this rule apply to | Array (of Strings) | text, bigquery, db2, mysql, oracle, postgres,redshift, snowflake,sqlite, tsql |
["text"] |
| rules | The regex rule you want | Array (of Strings) | Regular Expressions | ["your regex here"] |
| description | Allows a more in-depth description of the rule | String | Anything | "Descriptive comment that will appear in your report" |
| severity | Controls how violations are handled | String | error, warning, disabled |
"error" |
Rule file naming
The file name will be used as the source of rule metadata: A__B.toml (that's two underscores)
- Where A is the rule code (If the
codefield is not set in the file content, this value will be used as the default code) - Where B is a short rule description (If the
descriptionfield is not set in the file content, this value will be used as the default description)
Dialects
The way your regex rule is structured will vary depending on the dialect of SQL in use with your database (different keywords and syntax) so you may need explicitly declare the dialect that this rule is relevant for.
Flyway will identify the variety of SQL relevant to database based on the JDBC connection string and only apply relevant rules (so a rule declared for the Oracle dialect won't be applied when using a PostgreSQL database).
- The
TEXTdialect means the rule will be applied to all migrations regardless of the DB type Flyway is configured to use.
Severity
The severity field controls how violations of this rule are handled:
error- Violations will cause the check command to fail whencheck.code.failOnErroris enabledwarning- Violations will be reported but will not cause the operation to faildisabled- The rule will be ignored and no violations will be reported
The disabled severity level allows you to temporarily disable specific rules without removing them from your configuration.
Regular expression considerations
- Does case sensitivity matter to you ? If it doesn't then make the regex rules insensitive too with the prefix
(?i) - You will need to use the Java dialect of regex
File content example
code = "RX001"
dialects = ["TEXT"]
rules = ["(?i)(^|\\s)TO\\s+DO($|\\s|;)"]
description = "Phrase 'to do' remains in the code"
severity = "error"