andrew andrew - 8 months ago 39
Linux Question

How to exclude substring from string closing with whitespace?

I would like to exclude substring starting from '>' and closing with ' '.


content = "classTest>528 points"
substring = content['>' : ' ']
print substring # 528


If you do not want to use regular expressions (which has a bit of a learning curve), you can use this simpler but longer code.

content = "classTest>528 points"
i = content.find('>')
j = content.find(' ', i+1)
substring = content[i+1:j]