[英]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. LALL - 4302 坏了,而 LALL-4301 和 LALL 3305 正在修复中。
I want to capture:我想捕捉:
LALL - 4302, LALL-4301, LALL 3305
I see the pattern as it starts with " LALL " and captures the following numbers, special characters, and spaces, then stops once the number is followed by space.我看到该模式以“ LALL ”开头并捕获以下数字、特殊字符和空格,然后在数字后跟空格时停止。
How can I do it using RegEx?我如何使用 RegEx 做到这一点?
You may try using re.findall
:您可以尝试使用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']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.