[英]How to search for a word and then replace text after it using regular expressions in python?
[英]Python regular expressions, how to search for a word starting with uppercase?
我是Python的新手,我剛開始學習正則表達式。 我似乎無法弄清楚如何找到以大寫字母開頭的單詞。 例如:
text = '>:{abcd|}+)_(#)_@_Mitch_(@<$)_)*zersx!)Pamela@(_+)('
m = re.match(r'(\w+) (\w+)', text)
我希望它返回('Mitch', 'Pamela')
。
re.match()
完成此操作? re.split()
? 您可以僅將re.findall
與字母模式一起使用(因為\\w
組也將與_
字符匹配)。
>>> re.findall('[A-Z][A-Za-z]*', text)
['Mitch', 'Pamela']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.