10 likes | 128 Views
Lecture 3 Summary. Regular Expressions (continued from the previous lecture) 1. Disjunction : e.g. /cat|dog/ matches either the string cat or the string dog 2. Grouping : e.g. /gupp(y|ies)/ applies disjunction only to suffixes y and ies
E N D
Lecture 3 Summary • Regular Expressions (continued from the previous lecture) • 1. Disjunction : e.g. /cat|dog/ matches either the string cat or the string dog • 2. Grouping : e.g. /gupp(y|ies)/ applies disjunction only to suffixes y and ies • Precedence : Idea that one operator may take precedence over another is formalized by the operator precedence hierarchy • Advanced operators with examples : • a. Aliases for common sets of characters e.g. \w – any alphanumeric or space • b. Explicit numbers as counters e.g. /ab{24}z/ matches a followed by 24 b’s followed by z • c. Special characters are referred to using backslash (\) e.g. newline character \n • Substitution and memory in regular expressions • a. Substitution : s/regexp1/regexp2/ allows string characterized by one expression to be replaced by a different regular expression e.g. s/colour/color/ • b. Number operator : It is used to refer back to a particular subpart of a string using numbered memories called registers • e.g. /the (.*)er they (.*), the \1er they \2/ will match the bigger they were, the bigger they were but not the bigger they were, the bigger they will be • c. Subtitutions using memory are very useful in implementing NLP e.g. ELIZA