![]() |
VOOZH | about |
Given a string containing a mix of uppercase and lowercase letters, the task is to extract all sequences where one uppercase letter is immediately followed by one or more lowercase letters using Regex in Python. For example:
Input: geeAkAA55of55gee4ksabc3Ar2x
Output: ['Ak', 'Ar']
Let’s explore different methods to check and extract such sequences efficiently in Python.
The re.finditer() method finds all matches like re.findall(), but instead of returning a list, it yields match objects, which can be processed one by one.
Ak Ar
Explanation:
The re.findall() method directly extracts all sequences that match a given pattern and returns them as a list.
['Ak', 'Ar']
Explanation:
This variation ensures that each valid sequence is treated as a standalone word by using word boundary anchors (\b). It’s especially useful when such patterns appear next to numbers or symbols.
['Ak', 'Ar']
Explanation: