2. Write down the extended regular expression for following questions E.g. Socia
ID: 3873832 • Letter: 2
Question
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} (10 points, each 2 points)
1) Valid URL beginning with “http://”. (e.g. https://www.oakland.edu)
2) Valid variable name following the two rules below: Must begin with a letter of the alphabet, an underscore, or ( _ ), or a dollar sign ($) After the first initial letter, variable names may also contain letters and the digits 0 to 9.
3) Valid email address, assuming ‘ a-z’,’0-9’,’_‘,’.’ are valid characters for user id and domain name has to be end with either “.com” or “.net” (e.g. aabb_123.xy@g3.com, cdcd@12_3.net)
4) Phone number in any of the following format: 999-9999999,999999-9999, (999)-9999999. (Note: all of these formats should be matched by a single regular expression)
5) Valid HTML link tag with the format: <a … > ... </a> . (e.g. <a href="http://www.oreilly.com"> O’Reilly Media </a> , <a href="/file/test.txt"> Download Test </a> )
I JUST NEED 2 AND 4!
Explanation / Answer
1. http://[a-zA-Z0-9.-]*
Examples
http://www.chegg.com
http://www.oakland.edu
2. [a-zA-Z_$][a-zA-Z_$0-9]*
Examples
chegg34_underscore
_1chegg
$chegg12
3. [a-z0-9_.]*@[a-z0-9_.]*[.com|.net]
Examples
aabb_123.xy@g3.com
cdcd@12_3.net
4. ([0-9]{3}-[0-9]{7})|([0-9]{6}-[0-9]{4})|(([0-9]{3})-[0-9]{7})
Examples
999-9999999
999999-9999
(999)-9999999.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.