Part 5 - Regular Expressions Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a regular expression?

A

A regular expression is a set of special characters that define a pattern

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

What is the difference between a literal and a metacharacter?

A
  • A literal is just a character you wish to match in the target
  • A metacharacter is a special symbol that acts as a command to the regular expression parser
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In a regular expression, what does it indicate when the expression has the following form?
^example_expression$

A

The entire string must match the rest of the regex between the ^ and $

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
What is the meaning of
- \t
-\n
- . 
in regex?
A
  • \t matches any tab character
  • \n matches any new line character
  • . matches any character that is not \n
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between [example], [^example] and [e-l]?

A

[] - match any character contained in the set
[^] - match any character NOT in the set
[a-h] - match any character in the range

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

What is the difference between \w and \W?

A

\w matches any word character

\W matches any non-word character

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

What is the meaning of \s and \d in regex?

A
  • \s match any white-space character

- \d match any digit character

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

In regex, what is indicated by *, +, and ?

A
    • Indicates zero or more matches
    • Indicates one or more matches
  • ? Indicates zero or one match
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Using {}, how would you indicated n or more matches?

A

{n,}

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

What is the boolean OR equivalent metacharacter in regex?

A

|

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

How can a metacharacter, for example “?”, be used as a literal

A

Preface with \

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

How would you ensure that a string contains uppercase letters, no matter where they are placed?

A

(?=.*[A-Z])

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