I'm trying to extract digits from a unicode string. The string looks like raised by 64 backers
and raised by 2062 backers
. I tried many different things, but the following code is the only one that actually worked.
backers = browser.find_element_by_xpath('//span[@gogo-test="backers"]').text
match = re.search(r'(\d+)', backers)
print(match.group(0))
Since I'm not sure how often I'll need to extract substrings from strings, and I don't want to be creating tons of extra variables and lines of code, I'm wondering if there's a shorter way to accomplish this?
I know I could do something like this.
def extract_digits(string):
return re.search(r'(\d+)', string)
But I was hoping for a one liner, so that I could structure the script without using an additional function like so.
backers = ...
title = ...
description = ...
...
Even though it obviously doesn't work, I'd like to do something similar to the following, but it doesn't work as intended.
backers = re.search(r'(\d+)', browser.find_element_by_xpath('//span[@gogo-test="backers"]').text)
And the output looks like this.
<_sre.SRE_Match object at 0x000000000542FD50>
Any way to deal with this?!