1

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 2

2
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']
Sign up to request clarification or add additional context in comments.

1 Comment

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.
1
import re

def filter_digits(bar):
  return re.search("^\d+$", bar)

foo = "Q 000 1111 00001 0001 00 //SOME_STRING"
foo = foo.split(' ')
foo = filter(filter_digits, foo)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.