Python regular expressions, how to search for a word starting with uppercase?

后端 未结 1 805
醉话见心
醉话见心 2021-01-27 12:43

I\'m relatively new to Python, and I just started learning regular expressions. I can\'t seem to figure how to find a word that starts with an uppercase. For example:

         


        
相关标签:
1条回答
  • 2021-01-27 13:35

    You can simply use re.findall with just the letter pattern (as the \w group will also match the _ character).

    >>> re.findall('[A-Z][A-Za-z]*', text)
    ['Mitch', 'Pamela']
    
    0 讨论(0)
提交回复
热议问题