For example,
I have the string 'abdadqdqbdabdabdawb'
How can I find substrings, which start with 'a'
and end with 'b'
.
The output should be:
['ab', 'adqdqb', 'ab', 'ab', 'awb']
For example,
I have the string 'abdadqdqbdabdabdawb'
How can I find substrings, which start with 'a'
and end with 'b'
.
The output should be:
['ab', 'adqdqb', 'ab', 'ab', 'awb']
import re
re.findall(r'[Aa][^Bb]*[Bb]', 'abdadqdqbdabdabdawb')
>>> ['ab', 'adqdqb', 'ab', 'ab', 'awb']