Reputation: 1309
Example like "3-5/description"
. I'd like extract the numbers next to the dash -
, which are 3
and 5
in this example. The description
next to the /
is a str containing no number.
I want a tool to help me extract number from str like this like this func("3-5/description")
returns [3,5]
Upvotes: 0
Views: 46
Reputation: 153
You can do a regex match to capture the digits before and after the '-'
import re
def func(input):
return re.match(r'(\d+)[-](\d+)', x).groups()
func("3-5/description")
Upvotes: 1