regular expressions use the real power of regular expressionssince we could have just as easily used line find(to accomplish the same result the power of the regular expressions comes when we add special characters to the search string that allow us to more precisely control which lines match the string adding these special characters to our regular expression allow us to do sophisticated matching and extraction while writing very little code for examplethe caret character is used in regular expressions to match "the beginningof line we could change our program to only match lines where "from:was at the beginning of the line as followssearch for lines that start with 'fromimport re hand open('mbox-short txt'for line in handline line rstrip(if re search('^from:'line)print(linecodenow we will only match lines that start with the string "from:this is still very simple example that we could have done equivalently with the startswith(method from the string library but it serves to introduce the notion that regular expressions contain special action characters that give us more control as to what will match the regular expression character matching in regular expressions there are number of other special characters that let us build even more powerful regular expressions the most commonly used special character is the period or full stopwhich matches any character in the following examplethe regular expression mwould match any of the strings "from:""fxxm:"" :"or " !@ :since the period characters in the regular expression match any character search for lines that start with ' 'followed by charactersfollowed by ' :import re hand open('mbox-short txt'for line in handline line rstrip(if re search('^ :'line)print(linecode