[go: up one dir, main page]

Menu

#524 constant regex pattern should be static

open
nobody
rules (229)
5
2012-10-07
2009-02-20
No

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);

...

Discussion


Log in to post a comment.