Javascript Regular Expressions
-
A RegEx Example:
-
/somepattern/flags
-
Flags:
-
/g = global match, so any instances of instead of just first, /i = removes case sensitivity, /m = multiline, /y = sticky
-
The dot . :
-
. will match anything, exept line breaks. You can prevent this by escaping \ .
-
Meta Characters:
-
probably need to escape these in most cases: [ { ( ) ^ \ $ . | ? * +
-
Quantifiers
-
{} can be used like /a{n}/ where we find the letter 'a', n # of times, {n,} at least 'n' times, and {n,m} find at least n times, but no more than 'm' times
-
\d the digit finder
-
/\d/ or /[0-9]/ are equivalents, they'll find any digits
-
\w the alphanumberic and underscore finder
-
matches any alphanumeric character, equivalent to [A-Za-z0-9_]
-
\s the whitespace finder
-
matches a single white space character, including space, tab, form feed, line feed and other unicode spaces. Equivalent to [ \t\r\n].
-
[abcd] the character set
-
matches any one of the enclosed characters. You can specify a range of characters by using a hyphen. For example, [abcd] is the same as [a-d].
-
RegEx Reference
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp