0

I know how to capture a single instance of a substring between two markers:

Python 3 How to get string between two points using regex?

I tested that approach out with this string:

text = 'blah.blah${capture1}.${capture2}' 

I wanted to get all the substrings between these markers '${' and '}', but it only gets the first one.

>>> text = 'blah.blah${capture1}.${capture2}' >>> found = re.search('\$\{(.+?)\}', text) >>> found.groups() ('capture1',) >>> len(found.groups()) 1 >>> 

How do I get all of them?

1 Answer 1

1

You need a regex method that will find all the matches in a string. You should try re.findall('\$\{(.+?)\}', text) or re.finditer('\$\{(.+?)\}', text). The first will return a list, the second will return an iterable.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.