I have a string where I need to keep two key numbers and remove the rest which need to be converted to a string that can be used to slice data.
sample = 'range(0, 286)range(300, 511)'
I will always need the first two numbers (ex. 0 and 286
). Each of these numbers will not always be 0 and 286
. They can have multiple positions like 10 and 1000
or 100 and 10000
. They will always be in parentheses and have a comma to separate each number. The second set of numbers do not need to be extracted from the string.
Expected Output: My end product would be a string that looks like a slice:
print([sample])
[0:286]
How do I extract just the first two numbers from this text, zero and two-hundred-eighty-six?