IFB104 Lecture Notes - Lecture 8: Regular Expression, Substring, Ex-Gay Movement
Document Summary
Finding substrings: python"s built-in "find" method for character strings provides a way of finding fixed substrings in text: text. find(substring) It returns the position of the first occurrence of the substring in the text. It returns "-1" if the substring doesn"t occur in the text at all: the "rfind" method does the same thing but searches for the last occurrence. Finding multiple occurrences of substrings: you can also search from a particular position: text. find(substring, starting_pos, combining this capability with loops allows all occurrences of a substring to be found. In general, however, we need a more powerful way of expressing patterns if we want to find multiple occurrences of complex patterns. Finding general patterns in text using regular expressions. * is used as a wildcard to denote "everything", but in rgex, "*" is an operator which means repeat zero or more times.