Regular Expressions Flashcards

1
Q

RegEx matches for

/[wW]oodchuck/

A

Woodchuck
woodchuck

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

RegEx matches for

/[abc]/

A

‘a’, ‘b’, or ‘c’

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

RegEx matches for

/[1234567890]/

A

any digit

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

RegEx matches for

/[A-Z]/

A

An upper case letter

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

RegEx matches for

/[a-z]/

A

A lower case letter

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

RegEx matches for

/[0-9]/

A

A single digit

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

RegEx matches for

/[^A-Z]/

A

Not an upper case letter

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

RegEx matches for

/[^Ss]/

A

Neither ‘S’ nor ‘s’

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

RegEx matches for

/[^.]/

A

not a period

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

RegEx matches for

/[e^]/

A

either ‘e’ or ‘^’

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

RegEx matches for

/a^b/

A

the pattern ‘a^b’

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

RegEx matches for

/woodchucks?/

A

woodchuck or woodchucks

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

RegEx matches for

/colou?r/

A

color or colour

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

RegEx matches for

/beg.n/

A

any character between beg and n

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

RegEx matches for

A

start of a line

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

The three uses of the caret ^

A
  • to matcht the start of a line
  • to indicate a negation inside of square brackets
  • just to mean a caret
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

RegEx matches for

$

A

end of line

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

RegEx matches for

\b

A

word boundary

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

RegEx matches for

\B

A

non-word boundary

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

Kleene *

“cleany star”

A

Zero or more occurrences of the immediately previous character or regular expression.

21
Q

Kleene +

A

One or more occurrences of the immediately preceding character or regular expression.

22
Q

Wildcard expression

.

A

Matches any single character (except a carriage return)

23
Q

Anchors

A

Special characters that anchor regular expressions to particular places in a string.

The most common anchors are the caret ^ and the dollar sign $.

^ matches the start of a line.
$ matches the end of a line
\b matches a word boundary
\B matches a non-word boundary

24
Q

Disjunction

A

the pipe symbol |

/cat|dog/ matches either cat or dog

25
Precendence
Use parentheses ( and ) Enclosing a pattern in paretheses makes it act like a single character for the purposes of neighbouring operators like the pipe | and the Kleene*
26
Operator precedence hierarchy
Parenthesis `()` Counters `*` `+` `?` `{}` Sequences and anchors `the` `^my` `end$` Disjunction **I** | In that order.
27
# RegEx matches for \d
Any digit
28
# RegEx matches for \D
Any non-digit
29
# RegEx matches for \w
Any alphanumeric / underscore
30
# RegEx matches for \W
A non-alphanumeric
31
# RegEx matches for \s
Whitespace (space, tab)
32
# RegEx matches for \S
Non-whitespace
33
# RegEx matches for *
zero or more occurrences of the previous char or expression
34
# RegEx matches for +
one or more occurrences of the previous char or expression
35
# RegEx matches for ?
exactly zero or one occurrence of the previous char or expression
36
# RegEx matches for {n}
*n* occurrences of the previous char or expression
37
# RegEx matches for {n,m}
From *n* to *m* occurrences of the previous char or expression.
38
# RegEx matches for {n,}
At least *n* occurrences of the previous char or expression.
39
# RegEx matches for {,m}
up to *m* occurrences of the previous char or expression
40
newline
\n
41
tab
\t
42
# RegEx matches for \*
An asterisk "*"
43
# RegEx matches for \.
A period "."
44
# RegEx matches for \?
A question mark
45
# RegEx matches for \n
a newline
46
# RegEx matches for \t
a tab
47
Capture group
The use of parentheses to store a pattern in memory is called a **capture group**. Every time a capture group is used (i.e., parentheses surround a pattern), the resulting match is stored in a numbered **register**. If you match two different sets of parentheses, \2 means whatever matched the *second* capture group.
48
non-capturing group
We might want to use parenthesis for grouping, but don't want to capture the resulting pattern in a register. In that case, we use a non-capturing group, which is specified by putting the commands ?: after the open paren, in the form `(?: pattern )`
49
lookahead assertions
The operator `(?= pattern)` is true if `pattern` occurs, but is zero-width, i.e. the match pointer doesn't advance. The operator `(?! pattern)` only returns true if a pattern does not match, but again is zero-width and doesn't advance the curosor.