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
Q

Precendence

A

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
Q

Operator precedence hierarchy

A

Parenthesis ()
Counters * + ? {}
Sequences and anchors the ^my end$
Disjunction I

In that order.

27
Q

RegEx matches for

\d

A

Any digit

28
Q

RegEx matches for

\D

A

Any non-digit

29
Q

RegEx matches for

\w

A

Any alphanumeric / underscore

30
Q

RegEx matches for

\W

A

A non-alphanumeric

31
Q

RegEx matches for

\s

A

Whitespace (space, tab)

32
Q

RegEx matches for

\S

A

Non-whitespace

33
Q

RegEx matches for

*

A

zero or more occurrences of the previous char or expression

34
Q

RegEx matches for

+

A

one or more occurrences of the previous char or expression

35
Q

RegEx matches for

?

A

exactly zero or one occurrence of the previous char or expression

36
Q

RegEx matches for

{n}

A

n occurrences of the previous char or expression

37
Q

RegEx matches for

{n,m}

A

From n to m occurrences of the previous char or expression.

38
Q

RegEx matches for

{n,}

A

At least n occurrences of the previous char or expression.

39
Q

RegEx matches for

{,m}

A

up to m occurrences of the previous char or expression

40
Q

newline

A

\n

41
Q

tab

A

\t

42
Q

RegEx matches for

*

A

An asterisk “*”

43
Q

RegEx matches for

.

A

A period “.”

44
Q

RegEx matches for

\?

A

A question mark

45
Q

RegEx matches for

\n

A

a newline

46
Q

RegEx matches for

\t

A

a tab

47
Q

Capture group

A

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
Q

non-capturing group

A

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
Q

lookahead assertions

A

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.