2

How to find multiple occurrence of a pattern in a string and store all occurrences in a list as multiple elements. for example:

re.search('[A-Z]+',"assAAhhhAB").group(0)

would give me :

AA

whereas I want output as

['AA' ,'AB']

1 Answer 1

2

Use re.findall:

import re
print(re.findall('[A-Z]+',"assAAhhhAB"))
# => ['AA', 'AB']

See the Python demo

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

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.