Regular Expression Flashcards

1
Q

How to enclose a regex pattern?

A

/pattern/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What would [A-Za-z] mean?

A

Look for allcaps alphabet or lowercase alphabet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

?What does ^ signify at the start of a set [^pattern]?

A

It negates the set (look for everything but what is enclosed in the brackets)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What would /snow./ indicate?

A

The patters we are looking for starts with “snow” but can be followed by anything else but a newline character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the digits pre-defined classes?

A

\d: digit and \D: not a digit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the word pre-defined classes?

A

\w: a word and \W: not a word

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the whitespace pre-defined classes?

A

\s: whitespace and \S: not a whitespace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to specify repetitions?

A

{n}: exactly n repetitions
{m,}: at least m repetitions
{n,m}: at least n, no more than m

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the symbols for the number of repetitions?

A

asterisk: 0 or more
+: one or more
?: 0 or 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are anchors, and what do they do?

A

start with ^: forces pattern matching on the LEFT
end with $: forces pattern matching on the RIGHT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the modifiers and what do they do?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Write

List some of the methods to use regex with

A

string.replace
string.match // returns the matches
string.split // as seen before
string.search(regex) // return 0 if true, -1 if not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly