20 likes | 161 Views
Regex Challenge. Construct regular expressions for the following: Hint: use echo “<h4>” | [ e ] grep ‘<[hH][1-4]>’ SSN [[:digit:]]{3}-[[:digit:]]{2}-[[:digit:]]{4} A complete line that contains words “one”, “two” or “three” ^.* (one|two|three) .*$
E N D
Regex Challenge Construct regular expressions for the following: Hint: use echo “<h4>” | [e]grep ‘<[hH][1-4]>’ • SSN [[:digit:]]{3}-[[:digit:]]{2}-[[:digit:]]{4} • A complete line that contains words “one”, “two” or “three” ^.* (one|two|three) .*$ • A complete line that contains a date in a format: YYYY-MM-DD (19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]) • Unix file permission pattern in file listing [-ld][-rwxs]{3} • US phone number (\+[0-9])? *(\([0-9]{3}\))? *[0-9]{3}([ -])?[0-9]{4} • The beginning and the end of an HTML tag <\([A-z][A-z0-9]*\)[^>]*>.*<\1> • As 6, but extract the <TAG> value (whatever is between the tags) <\(tag\)[^>]*>\(.*\)</\1>\2 Prof. Andrzej (AJ) Bieszczad Email: andrzej@csun.edu Phone: 818-677-4954
Regex Challenge • IP address [[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3} • IP address with 0-255 scope for each octet (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) • Floating point number [-+]?([0-9]*\.[0-9]+) • As before, but with exponents [-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)? • URL (ftp\:\\\\|http\:\\\\|mailto\:\\\\)?([-_[:alnum:]]+\@)?(www\.)?[-_[:alnum:]]+(\.[-_[:alnum:]]+)+(\:[0-9]+)? • An email address [[:alnum:]!#\$%-+._]+@[[:alnum:]_]+(\.[[:alnum:]_]+)+ Prof. Andrzej (AJ) Bieszczad Email: andrzej@csun.edu Phone: 818-677-4954