首页 > 解决方案 > How to match only letters from a string containing alphanumeric and symbols?

问题描述

log : Description: "AMEND - 04 ACCEPTED" Output: AMEND ACCEPTED

I have tried to write regex as Description:\s"([A-Z]+)". but its matching only 1st word.

标签: regex

解决方案


根据您的工具或语言,正则表达式 find all 可能在这里最有意义。你可以在模式上匹配\b[A-Z]+\b

这是一个演示

在 Python 中,我们可以尝试:

inp = "AMEND - 04 ACCEPTED"
matches = re.findall(r'\b[A-Z]+\b')
print(matches)  # ['AMEND', 'ACCEPTED']

推荐阅读