Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Choose match(es) for each given basic/extended regular expression (maybe multipl

ID: 3885557 • Letter: C

Question

Choose match(es) for each given basic/extended regular expression (maybe multiple correct matches) and describe the pattern of matched string for 3), 4), 5), 6), 11).

1) ‘a[ab]*a’ (a)ababa (b) aaba (c) aabab (c) aabab (d) aabbaa (e)aa

2) ‘a(bc)?’ (a) abc (b) a(bc)? (c) a(bc (d) a (e) abcbc

3) ‘.[ind]*’ (a) wind (b) window (c) end (d) good (e)will

4) ‘[a-z]+[a-z]’ (a) a+b+c (b) +b (c) x (d) x+1 (e) x+a

5) ‘[a-z] (+[a-z])+’ (a) a+b+c (b) +b (c) x (d) x+1 (e) x+a

6) ‘a.[bc]+’ (a)azbc (b)az (c)azbcbc (d)acc (e)acz

7) ‘a.[0-9]’ (a)azz (b)a0z (c)a01 (d)a0a (e)aza

8) ‘[a-z]+[.?!]’ (a)good! (b)Book. (c)hard? (d)cool?hot (e)nothing

9) ‘[a-z]+[.?!]s*[A-Z]’ (hint: s matches any whitespace characters) (a)Grade. A (b) book. Z (c) E. G (d) Level. a (e)index?a

10) ‘(very )+(cool )?(good|bad) weather’
(a)good weather (b) very good weather (c) cool weather

(d) very cool bad weather (e)cool good weather

11) ‘-?[0-9]+’
(a)3312 (b) -2231 (c) +32 (d) 0.5 (e)2/3

12) ‘-?[0-9]*.?[0-9]*’
(a)3312 (b) -2231 (c) +32 (d) 0.5 (e)2/3

Explanation / Answer

(1)a[ab]*a

Square brackets in a regular expression are used to indicate a character set. A character set will match any character in the set.

The asterisk character means that the subpattern can occur zero or more times.

So the correct options for this are:

(a) ababaa   (b) aaba (d) aabbaa (e) aa

(2) a(bc)?

The question mark means that the subpattern can be missing or it can occur exactly once.

Parentheses can be used to define a subpattern within a regular expression.

So the correct options are :

(a) abc

(3) .[ind]*

The full stop character matches any single character of any sort (apart from a newline).

So the correct options are:

(a) wind   (c) end

(4) [a-z]+[a-z]

the regular expression "[a-z]+[a-z]" means: any number of any(English) lowercase letter, followed by any single (English) lowercase letter.

So the correct options are:

None of the options match the pattern

Hope this helps...

BEST WISHES!