Search code examples
pythonstringfindpartialsurround

Python: Find Surrounding parts of a string with irrelevant section in the middle


So I have a large string with several similar things. I want to find part of a string but have part of it be irrelevant.

For example: "0" blah"11" "0" blah"3" "0" blah"6" "0" blah"600" "0"

I want to find ' blah"..." ' Where '...' is the number and I can get the value of '...'

Is there an easy way to do that?


Solution

  • >>> import re
    >>> re.findall(r'blah"(\d+)"','"0" blah"11" "0" blah"3" "0" blah"6" "0" blah"600" "0"')
    ['11', '3', '6', '600']