WordPress-Coding-Standards
WordPress-Coding-Standards copied to clipboard
Some regex best practices
With the regex functions, there are some best practices we could advise on /often made "mistakes" which we could warn people about.
I'm thinking along the lines of:
- Use of
/as delimiter -> advise to use other delimiter - Use of variables in the regex -> use
preg_quote() - Use of
gmodifier -> Not used in PHP usepreg_match_all()function instead - Use of
sandmmodifier in one regex -> they don't go together, review regex
Additionally the sniff could potentially check for:
- non-PCRE syntaxes used in the regex
- modifiers which are not implemented/available in PHP
This sniff would go into the extra ruleset.
Opinions ?
💯 brilliant!