13 окт. 2014 г.

JavaScript RegExp simplification


  • [0-9] could be replaced with \d
  • ($|&|\s) could be simplified to [$&\s] or to ([$&\s]) if you need capturing
  • a*.* could be simplified to just .*
  • similarly, a+.* could be simplified to .*
  • non-capturing group (?:foo) has slightly better performance than capturing (foo)
  • {0,1} could be replaced with ?
  • {1} could be omitted
Link to dead simple RegExp validator/optimizer