Skip to content

Instantly share code, notes, and snippets.

@maolion
Last active October 13, 2015 15:18
Show Gist options
  • Save maolion/4215533 to your computer and use it in GitHub Desktop.
Save maolion/4215533 to your computer and use it in GitHub Desktop.
RegExp Patterns
//@author https://github.com/vilic
var nullLiteralRegex = /null/;
var booleanLiteralRegex = /true|false/;
var stringLiteralRegex = /(["'])(?:(?!\1|[\r\n\u2028\u2029\\])[\s\S]|\\(?:['"\\bfnrtv]|[^'"\\bfnrtv\dxu\r\n\u2028\u2029]|0|x[\da-fA-F]{2}|u[\da-fA-F]{4})|\\(?:[\r\n\u2028\u2029]|\r\n))*\1/;
var numericLiteralRegex = /(?:(?:(?:0|[1-9]\d*)(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|0[xX][\da-fA-F]+)/;
var regexLiteralRegex = /\/(?:[^\r\n\u2028\u2029*/\[\\]|\\[^\r\n\u2028\u2029]|\[(?:[^\r\n\u2028\u2029\]\\]|\\[^\r\n\u2028\u2029])*\])(?:[^\r\n\u2028\u2029/\[\\]|\\[^\r\n\u2028\u2029]|\[(?:[^\r\n\u2028\u2029\]\\]|\\[^\r\n\u2028\u2029])*\])*\/[gimy]{0,4}/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment