I'd say that shorter shouldn't be the goal in itself, unless you're golfing (in which case, you want to be on Code Golf and Coding Challenges). A better criterion is to have the simplest code that achieves the desired aim.
A major contribution to simplicity is to replace the explicit close of
f with a
with open('text.txt', 'r') as f:
# do the addition
# f is closed before we get here
Another simplification is to use
map as suggested in styvane's answer; however, it may be more efficient to read the file a line at a time rather than slurping the entire contents into memory if it's very long.
We could also make the code more efficient by compiling the regular expression just once.
Following that, we might want to make the code more reusable and testable. I would separate into a function that does the summing but doesn't care where the stream comes from (file, pipe, socket, string), and have tests for that. Then simply call it with the input file stream.
That reusable function including unit-tests looks like this:
"""Return the total of all the digit strings found in the input stream
>>> from io import StringIO
digit_pattern = re.compile(r'\d+')
return sum(sum(map(int, digit_pattern.findall(line))) for line in stream)
if __name__ == "__main__":
And we can use it very simply:
That's not shorter, but it is better in the ways I've described (more efficient, flexible and maintainable).