WordPress-Coding-Standards icon indicating copy to clipboard operation
WordPress-Coding-Standards copied to clipboard

Some regex best practices

Open jrfnl opened this issue 9 years ago • 1 comments

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 g modifier -> Not used in PHP use preg_match_all() function instead
  • Use of s and m modifier 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 ?

jrfnl avatar Jul 25 '16 17:07 jrfnl

💯 brilliant!

westonruter avatar Jul 25 '16 20:07 westonruter