Introduction to Regular Expressions Regex Challenge Construct regular

  • Slides: 2
Download presentation
Introduction to Regular Expressions Regex Challenge Construct regular expressions for the following: Hint: use

Introduction to Regular Expressions Regex Challenge Construct regular expressions for the following: Hint: use echo “<h 4>” | [e]grep ‘<[h. H][1 -4]>’ 1. SSN [[: digit: ]]{3}-[[: digit: ]]{2}-[[: digit: ]]{4} 2. 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-z 0 -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 1

Introduction to Regular Expressions Regex Challenge 1. IP address [[: digit: ]]{1, 3}. [[:

Introduction to Regular Expressions Regex Challenge 1. IP address [[: digit: ]]{1, 3}. [[: digit: ]]{1, 3} 2. 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]? ). (25[0 -5]|2[0 -4][0 -9]|[01]? [0 -9]? ) 3. Floating point number [-+]? ([0 -9]*. [0 -9]+) 4. As before, but with exponents [-+]? ([0 -9]*. )? [0 -9]+([e. E][-+]? [0 -9]+)? 5. URL (ftp: \\|http: \\|mailto: \\)? ([-_[: alnum: ]]+@)? (www. )? [-_[: alnum: ]]+(. [_[: alnum: ]]+)+(: [0 -9]+)? 6. An email address [[: alnum: ]!#$%-+. _]+@[[: alnum: ]_]+(. [[: alnum: ]_]+)+ Prof. Andrzej (AJ) Bieszczad Email: andrzej@csun. edu Phone: 818 -677 -4954 2