Here are three predefined character classes: \\d, \\s, and \\w. Describe each on
ID: 3570942 • Letter: H
Question
Here are three predefined character classes: d, s, and w. Describe each one, and rewrite its equivalent using the square bracket syntax.
Consider the regular expression (dog){3}. Identify the two subexpressions. What string does the expression match?
Write an expression that will match a person's name only if that person's first name and last name are the same.
Write a regular expression that matches all strings over the alphabet {a, b, c} that contain:
a)starts and ends with a
b)at most one a
at least two a's
Explanation / Answer
Question: Here are three predefined character classes: d, s, and w. Describe each one, and rewrite it using square brackets.
Answer:
d Matches any digit. [0-9]
s Matches any white space character. [ -x0B ]
w Matches any word character. [a-zA-Z_0-9]
Question: Consider the regular expression (dog){3}. Identify the two subexpressions. What string does the expression match?
Answer: The expression consists of a capturing group, (dog), followed by a greedy quantifier {3}. It matches the string "dogdogdog".
Question: Use a backreference to write an expression that will match a person's name only if that person's first name and last name are the same.
Answer: ([A-Z][a-zA-Z]*)s
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.