I have sentence like "Q 000 1111 00001 0001 00 //SOME_STRING" I wanted to add except Q and //SOME_STRING in a List in Python in the Result only List contains 000 1111 00001 0001 00. How can I do this?
2 Answers
import re
data = "Q 000 1111 00001 0001 00 //SOME_STRING"
digits = re.findall(r"\b\d+\b",data)
Test
>>> re.findall(r"\b\d+\b","Q 000 1111 00001 0001 00 //SOME_STRING234zzzz")
['000', '1111', '00001', '0001', '00']
1 Comment
YOU
The result will be "['000', '1111', '00001', '0001', '00', '234']" without \b, which means word boundary. If your string will never contains digits, may be you don't need that.