Regular Expression Flashcards
How to enclose a regex pattern?
/pattern/
What would [A-Za-z] mean?
Look for allcaps alphabet or lowercase alphabet
?What does ^ signify at the start of a set [^pattern]?
It negates the set (look for everything but what is enclosed in the brackets)
What would /snow./ indicate?
The patters we are looking for starts with “snow” but can be followed by anything else but a newline character
What are the digits pre-defined classes?
\d: digit and \D: not a digit
What are the word pre-defined classes?
\w: a word and \W: not a word
What are the whitespace pre-defined classes?
\s: whitespace and \S: not a whitespace
How to specify repetitions?
{n}: exactly n repetitions
{m,}: at least m repetitions
{n,m}: at least n, no more than m
What are the symbols for the number of repetitions?
asterisk: 0 or more
+: one or more
?: 0 or 1
What are anchors, and what do they do?
start with ^: forces pattern matching on the LEFT
end with $: forces pattern matching on the RIGHT
What are the modifiers and what do they do?
i: placed at the end, the case is ignored
g: global, matches all occurences
m: multiline, only works with ^ (start of line) and $ (end of line)
Write
List some of the methods to use regex with
string.replace
string.match // returns the matches
string.split // as seen before
string.search(regex) // return 0 if true, -1 if not