line line rstrip(if re search('^ \ *[ - ]+'line)print(linecodewhen we run the programwe see the data nicely filtered to show only the lines we are looking for -dspam-confidence -dspam-probability -dspam-confidence -dspam-probability but now we have to solve the problem of extracting the numbers while it would be simple enough to use splitwe can use another feature of regular expressions to both search and parse the line at the same time parentheses are another special character in regular expressions when you add parentheses to regular expressionthey are ignored when matching the string but when you are using findall()parentheses indicate that while you want the whole expression to matchyou only are interested in extracting portion of the substring that matches the regular expression so we make the following change to our programsearch for lines that start with 'xfollowed by any non whitespace characters and ':followed by space and any number the number can include decimal then print the number if it is greater than zero import re hand open('mbox-short txt'for line in handline line rstrip( re findall('^ \ *([ - ]+)'lineif len( print(xcodeinstead of calling search()we add parentheses around the part of the regular expression that represents the floating-point number to indicate we only want findall(to give us back the floating-point number portion of the matching string the output from this program is as follows[' '[' '[' '