What you’re looking for is a parser, instead of a regular expression match. In your case, I would consider using a very simple parser, split()
:
s = "VALUE 100 234 568 9233 119"
a = s.split()
if a[0] == "VALUE":
print [int(x) for x in a[1:]]
You can use a regular expression to see whether your input line matches your expected format (using the regex in your question), then you can run the above code without having to check for "VALUE"
and knowing that the int(x)
conversion will always succeed since you’ve already confirmed that the following character groups are all digits.