regular expressions are used to solve common problemgiven stringdetermine whether that string matches given pattern andoptionallycollect substrings that contain relevant information they can be used to answer questions likeis this string valid urlwhat is the date and time of all warning messages in log filewhich users in /etc/passwd are in given groupwhat username and document were requested by the url visitor typedthere are many similar scenarios where regular expressions are the correct answer many programmers have made the mistake of implementing complicated and fragile string parsing libraries because they didn' know or wouldn' learn regular expressions in this sectionwe'll gain enough knowledge of regular expressions to not make such mistakesmatching patterns regular expressions are complicated mini-language they rely on special characters to match unknown stringsbut let' start with literal characterssuch as lettersnumbersand the space characterwhich always match themselves let' see basic exampleimport re search_string "hello worldpattern "hello worldmatch re match(patternsearch_stringif matchprint("regex matches"the python standard library module for regular expressions is called re we import it and set up search string and pattern to search forin this casethey are the same string since the search string matches the given patternthe conditional passes and the print statement executes bear in mind that the match function matches the pattern to the beginning of the string thusif the pattern were "ello world"no match would be found with confusing asymmetrythe parser stops searching as soon as it finds matchso the pattern "hello womatches successfully let' build small example program to demonstrate these differences and help us learn other regular expression syntaximport sys