This is a draft cheat sheet. It is a work in progress and is not finished yet.
Methods
regex.test(string) |
returns bool |
string.match(regex) |
returns regex from string w/ extract, index and input |
string.replace(regex, input) |
replaces regex in string with input (can be function or string) |
string.replace(regex, '$a $b') |
a & b can be capture groups from regex |
Character Classes
/\syntax\ |
syntax |
|
\w |
[A-Za-z0-9_] |
\W |
[^A-Za-z0-9_] |
\d |
[0-9] |
\D |
[^0-9] |
\s |
whitespaces and return |
\S |
NON whitespaces and return |
|
|
Patterns
/regex/ |
litteral match |
/regex|moreregex/ |
Literal match w/ different possibilities |
/?/ |
lazy search |
/^a/ |
returns a if first |
/a$/ |
returns a if last |
|
/(?=a)/ |
returns if a is present |
/(?!a)/ |
returns if a is NOT present |
|
/./ |
wildcard character |
/a?/ |
a optional |
|
/[a+]/ |
a or aa as single match (1 or more) |
/[Aa*]/ |
Aa or A as single matches (0 or more) |
|
/[A-z]{a,b}/ |
min a, max b |
/[A-z]{x,}/ |
min x times |
/[A-z]{x}/ |
only x times |
/[A-z],{x}/ |
max x times |
|
|
Flags
/regex/flag |
structure |
|
i |
ignores case |
g |
global, searches multiple times |
Character Classes & Groups
/[a-z]/ |
a thru z |
/[a-zA-Z]/ |
a thru z and A thru Z |
/[^a]/ |
exclude a |
|
/(\w)/ |
group |
/(\w)\1/ |
reuses (\w) |
|