2. Write down the extended regular expression for following questions Eg. Social
ID: 3750769 • Letter: 2
Question
2. Write down the extended regular expression for following questions Eg. Social security number in the format of 999-99-9999. Answer: [0-93)-[0-9112)-[0-9114) 1) 1) Valid date format in the format of MMM-DD,YYYY. Note: the first character of the month is capitalized (eg. 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 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. (eg #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)Explanation / Answer
1. [A-Z][a-z]{2}-[0-9]{2},[0-9]{4}
2. [a-zA-Z_]+[a-zA-Z_-]*[0-9]+
3. #[A-Z][a-z ]*.
4. [0-9]{1,3}
5. [0-9]{3}[-]?[(]?[0-9]{3}[)]?[0-9]{4}
? -- repeats once or not at all
* -- repeats zero or more times
+ -- repeats once or more times
{x} -- repeats n times only
{a, b} -- repeats at least a times but less than b times
Let me know if you have any queries or clarifications.... :)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.