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

Regular Expression 1. Chose match(es) for each given basic/extended regular expr

ID: 3746993 • Letter: R

Question

Regular Expression 1. Chose match(es) for each given basic/extended regular expression (maybe multiple correct matches) and describe the pattern of matched

5) ‘a(a|b)*a’ (a)ababa (b) aaba (c) aabab (d) aabbaa (e)aa

6) ‘[a-z](+[a-z0-9])+’ (a) x+9 (b) x+y (c) 1 (d) y (e) x++y

7) ‘a (bc)*z’ (a)azbc (b) az (c) azbcbc (d) acc (e)acz

8) ‘a.*[0-9]’ (a)a|1 (b) a*2 (c) ab2 (d) abc (e)aaa

9) ‘[a-t]+[.?!+]’ (a)bash! (b) c (c) Java? (d) python! (e)c++

10) ‘[a-z]+[.?!]s*[A-Z]’ (hint: s matches any whitespace characters) (a)o. year (b) x?y (c) U.S. (d)Hello!HELLO (e)index?a

11) ‘(verys)?(cools)+(good|bad) weather’ (a)very weather (b) very cool weather (c) good weather (d) very cool good weather (e)cool bad weather

12) ‘-?([0-9]|([1-9][0-9]))’ (a)123 (b) -123 (c) -0 (d) -2.2 (e) 1.2

13) ‘-?[0-9]*.?[0-9]*’ (a)123 (b) -123 (c) -0 (d) -2.2 (e) 1.2 2.

Write down the extended regular expression for following-

2) An account name which is 8 to 15 characters long, begins with a letter or underscore, ends with a digit, and composed by letters, numbers, underscores and hyphens. (e.g. my_Name1, cat_2, One-1)

3) A single-line comment starting with a # and continuing until the end of the line. Note: only whitespace is allowed between the start of the line and the comment. (e.g. #This program outputs the string hello world.  

4) Integers in the range between 00 and 99. (e.g. 0, 00, 01, 15, 55, 59,99)

5) Phone number in any of the following format: 999-(999)9999, 999999-9999, 999-999-9999. (Note: all of these formats should be matched by a single regular expression)

( can you give me a good explanation of how to do those.(not just the ans).)

Explanation / Answer

1) a,b,d,e

2) a,d

3) a,b,c,d,e

Describe: [ind]* will find any of the letter i,n,or d in the string.

4) no pattern will match from options

Describe: [a-z]+ will find letters one and unlimited times,and [a-z] find single letter.

+ Quantifier — Matches between one and unlimited times,

5) a

Describe: [a-z] find single character. + will find '+' operator.

(+[a-z])+ means one or more times + followed by letter ..like +a+b+d

6) a,c,d

Describe: a.[bc]+ Matches a then any single character followed by one or more b or c.

dot Matches any single character except .

7) c

Describe: there should be one digit at the end

8) a,c

Describe: any number of character follwed by either . or ? or !

9) b

10) no option will match because all options have white space present but in regular

expression there is no expression to handle white spaces.

11) a,b

Describe: -?[0-9]+ matches -(dash) zero or one time followed by one or more digits.

? Matches the previous element zero or one time.

12) a,b,d

Describe: -?[0-9]*.?[0-9]* matches -(dash) zero or one time followed by one or more digits followed by

.(dot) then followed by zero or more digits.

? Matches the previous element zero or one time.