Loading ...
Sorry, an error occurred while loading the content.

Re: [jslint] Preferred convention for multiple regex matches? (UNCLASSIFIED)

Expand Messages
  • Cheney, Edward A SSG RES USAR USARC
    Classification: UNCLASSIFIED Joshua, Use a single regex for all possible conditions: (/(first pattern)|(second pattern)/) Then you can test with a single
    Message 1 of 2 , Feb 25, 2011
    • 0 Attachment
      Classification: UNCLASSIFIED
      Joshua,

      Use a single regex for all possible conditions:
      (/(first pattern)|(second pattern)/)

      Then you can test with a single condition. The pipe is similar to the JS double pipe operator, so in this example if either the first set or the second set is true then you are done.

      Just be wary if you are executing this regex in a loop. Regular expressions are processed via an internal API between the interpreter and the code the interpreter is running on, so you take a performance hit each time you access that API. Regular expressions are faster to process than JS instructions though, so they are best outside of a loop using the "g" switch for global.

      Austin Cheney, CISSP
      http://prettydiff.com/
      Classification: UNCLASSIFIED
    Your message has been successfully submitted and would be delivered to recipients shortly.