Topic 9 - Regular Expressions Flashcards

1
Q

matches any single character except newline

A

.

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

matches zero or more occurrence of the previous single character

A

*

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

escape character

A

\

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

matches the beginning of a line

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

matches the end of a line

A

$

do not use $ with double quotes - problems with the shell

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

-matches a single character in a set or range of characters

A

[..]

Eg: a[bc]
matches a string that has a followed by b or c
- combine […] with * to match repeated sets

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

[^…]

A

matches the complement of whats inside the square brackets

Eg: [^a-zA-Z] will match a string that does not have any of the English letters

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

\less-than-sign

A

matches the BEGINNING of a regular expression word

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

>

A

matches the END of a regex word

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

(….)

\n

A
  • remembers a portion of regular expression

- recalls the remembered portion where n is a digit from 1 to 9

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

X{m}

X{m,n}

A
  • matches exactly m repeated of the one character regular expression X
  • matches m to n repeats of X
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

X{m,}

A

matches m or more repeats of X

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

matches simply m or fewer repeats of X

A

X{,m}

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

matches a string that has a $ before one digit

A

$\d

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

matches any string that starts with The

A

^The

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

matches a string that ends with end

A

end$

17
Q

Matches lines which only have the words:

The end

A

^The end$

18
Q

matches a string that has ab followed by one or more c

A

abc+

19
Q

matches a string that has ab followed by zero or more c

A

abc*

20
Q

matches a string that has ab followed by zero or one c

A

abc?

21
Q

matches a string that has ab followed by 2 c

ie: abcc

A

abc{2}

22
Q

What are the quantifier operators?

A
  • ,+ ,? and {}
23
Q

matches a string that has ab followed by 2 or more c

A

abc{2,}

24
Q

matches a string that has ab followed by 2 up to 5 c

A

abc{2,5}

25
Q

matches a string that has a followed by zero or more

copies of the sequence bc

A

a(bc)*

26
Q

matches a string that has a followed by 2 up to 5
copies of the sequence bc
Eg: abcbc
abcbcbcbc

A

a(bc){2,5}

27
Q

What are the character classes?

A

\d \w \s and .

\d matches a single character that is a digit
\w matches a word character (alphanumeric character plus underscore)

\s matches a whitespace character (includes tabs and line breaks)
. matches any character

28
Q

Match a single digit

A

\d

29
Q

matches a single non-digit character

A

\D

30
Q

matches a single non-word character

A

\W

31
Q

matches a single non-space character

A

\S

32
Q

matches the same text that was

matched by the first capturing group

A

([abc])\1