Inspectopedia
 
2024.3

Dynamic regular expression can be replaced by compiled 'Pattern'

Warning
New
Last modified: 03 December 2024

Reports calls to the regular expression methods (such as matches() or split()) of java.lang.String using constant arguments.

Such calls may be profitably replaced with a private static final Pattern field so that the regular expression does not have to be compiled each time it is used.

Example:

After the quick-fix is applied: