this is particularly powerful when combined with the ability to indicate that character can be repeated any number of times using the or characters in your regular expression these special characters mean that instead of matching single character in the search stringthey match zero-or-more characters (in the case of the asteriskor one-or-more of the characters (in the case of the plus signwe can further narrow down the lines that we match using repeated wild card character in the following examplesearch for lines that start with from and have an at sign import re hand open('mbox-short txt'for line in handline line rstrip(if re search('^from+@'line)print(linecodethe search string ^from+will successfully match lines that start with "from:"followed by one or more characters +)followed by an at-sign so this will match the following linefromstephen marquard@uct ac za you can think of the wildcard as expanding to match all the characters between the colon character and the at-sign from+it is good to think of the plus and asterisk characters as "pushyfor examplethe following string would match the last at-sign in the string as the pushes outwardsas shown belowfromstephen marquard@uct ac zacsev@umich eduand cwen @iupui edu it is possible to tell an asterisk or plus sign not to be so "greedyby adding another character see the detailed documentation for information on turning off the greedy behavior extracting data using regular expressions if we want to extract data from string in python we can use the findall(method to extract all of the substrings which match regular expression let' use the example of wanting to extract anything that looks like an email address from any line regardless of format for examplewe want to pull the email addresses from each of the following lines