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





Part II: Regular Expression 1. Chose match(es) for each given basic/extended regular expression (maybe multiple correct matches) and describe the pattern of matched string for 3), 4), 6), 11). e.g. 'ab+a' (extended regex) a) ababa b) aba c)abba d)aabbaa e)aa Answer: b,c; Pattern : The matched string should begin and end with 'a' and 'b'occurs at least once between leading and ending 'a') Note: 1) to 5 are basic regexes; 1) a(ab)*a' (b) aaba (c) aabab (d) aabbaa (e)aa (a)ababa 2) a?[bc]* (a) abc (b) a?[bc] (c) a[bc (d) a? (e) abcbc 3) *.[nd]*) (a) wind (b) window (c) end (d) good (e)will 4) '[a-z]+[0-9] (a) a++ (b) aa++ (c)6+ Note: 5) to 12) are extended regexes. (d) a+6 (e) aa+1 5) a(alb)*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)al1 (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) '(very\s)?(cool\s)+(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 (0)-0 (d) -2.2 (e) 1.2 13)-?[0-9]*\.?[0-9]*' (a)123 (b) -123 (0) 0 (d) -2.2 (e) 1.2 2. Write down the extended regular expression for following questions. E.g. Social security number in the format of 999-99-9999. Answer: [0-9]{3}-[0-9]{2}-[0-9]{4} 1) 1) Valid date format in the format of MMM-DD,YYYY. Note: the first character of the month is capitalized. (e.g. May-09,2008 Apr-19,2018 Jan-01,2000) 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_Namel, 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)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
