constant regex pattern should be static
A source code analyzer
Brought to you by:
adangel,
juansotuyo
I'd like to suggest a new rule (for the optimization category). I often see code where regular expressions are created from constant string literals and those regular expression patterns are created every time that code is executed. Instead the regular expression should be static.
Bad:
...
Pattern.compile(constantLiteral);
...
Better:
static Pattern pattern = Pattern.compile(constantLiteral);
...