Skip to content Skip to sidebar Skip to footer

Regex: Get All Numeric And Special Characters Starting With Specific Letters, Stop When Space Occurs After Number

I have this text example: LALL - 4302 is broken, while LALL-4301 and LALL 3305 are being fixed. I want to capture: LALL - 4302, LALL-4301, LALL 3305 I see the pattern as it star

Solution 1:

You may try using re.findall:

inp = "LALL - 4302 is broken, while LALL-4301 and LALL 3305 are being fixed."
matches = re.findall(r'\bLALL\s*-?\s*\S+', inp)
print(matches)

This prints:

['LALL - 4302', 'LALL-4301', 'LALL 3305']

Post a Comment for "Regex: Get All Numeric And Special Characters Starting With Specific Letters, Stop When Space Occurs After Number"