Regular expressions Flashcards

1
Q

What are regular expressions used for?
a) To perform mathematical calculations
b) To verify and match strings according to patterns
c) To handle exceptions in Java
d) To store complex data structures

A

b) To verify and match strings according to patterns

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

What is the main purpose of the Pattern class in Java?
a) To hold string values
b) To store regular expression patterns
c) To concatenate multiple strings
d) To sort an array of strings

A

b) To store regular expression patterns

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

In a regular expression, what does [0-9]{3} represent?
a) Three alphabetical characters
b) Three numeric digits
c) A mix of letters and numbers
d) Any three symbols

A

b) Three numeric digits

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

Why is the dash character escaped in a regular expression pattern like \-?
a) To indicate it’s a literal dash rather than a special character
b) To allow it to match any character
c) To make it optional in the pattern
d) To denote the start of a new line

A

a) To indicate it’s a literal dash rather than a special character

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

What method is used on a Matcher object to check if a pattern exists within a string?
a) match()
b) find()
c) check()
d) verify()

A

b) find()

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

What does the [B|R] pattern check for in a regular expression?
a) Either a B or R as the first character
b) Any letter between B and R
c) Only lowercase b or r
d) A space or a new line character

A

a) Either a B or R as the first character

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

In the context of regular expressions, what is the purpose of the method matchName()?
a) To compile a pattern from a string
b) To check for matches and print a greeting based on the result
c) To convert all text to uppercase
d) To find and replace characters in a string

A

b) To check for matches and print a greeting based on the result

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

What does the regular expression [Vic|][[T|t]oria] aim to match?
a) Strings starting with Vicky only
b) Variations of the name Victoria, including nicknames
c) Any name ending with ria
d) All names beginning with T

A

b) Variations of the name Victoria

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

What is the primary advantage of using regular expressions over contains(), endsWith(), and startsWith()?
a) Regular expressions are faster
b) They allow more flexible and abstract pattern matching
c) They ignore case sensitivity automatically
d) They are built only for numerical data

A

b) They allow more flexible and abstract pattern matching

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

In regular expressions, what does the pipe symbol | represent?
a) A literal character
b) An alternative or choice
c) The end of a string
d) A space character

A

b) An alternative or choice

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