简体   繁体   English

正则表达式:获取以特定字母开头的所有数字和特殊字符,当数字后出现空格时停止

[英]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.

相关问题 正则表达式:在特定字符串后获取数字、空格或“-”字符 - Regex: get numeric, space, or "-" characters after specific string 正则表达式删除所有数字和特殊字符,但空格和字母 - Regex to strip all numbers and special characters but space and letters 正则表达式:特殊字符之间的数字(但不是所有数字) - Regex: Numbers between special characters (but not all number) 正则表达式:删除字母之间不是撇号的所有特殊字符 - Regex: Remove all special characters that are not apostrophes between letters 正则表达式获取具有特定字母的所有单词列表(unicode字形) - Regex to get list of all words with specific letters (unicode graphemes) 正则表达式:获取数字后的所有字符 - Regex: get all characters after numbers Python 正则表达式提取数字字符和其他特殊字符 - Python RegEx expression to extract numeric characters AND other special characters 正则表达式匹配字母,数字和一些特定字符? - Regex to match letters, numbers and some specific characters? 正则表达式可替换除小写字母,数字字符,下划线和破折号之外的所有内容 - regex to replace everything except lowercase letters, numeric characters, underscores, and dashes 在 Python pandas 中使用正则表达式查找组合数字和字母的特定字符序列 - Find specific sequence of characters combining number and letters using regex in Python pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM