Capture all consecutive all-caps words with regex in python?

后端 未结 4 958
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-10 20:08

I am trying to match all consecutive all caps words/phrases using regex in Python. Given the following:

    text = \"The following words are ALL CAPS. The follow         


        
4条回答
  •  一整个雨季
    2021-02-10 20:54

    Your regex is relying on explicit conditions(space after letters).

    matches = re.findall(r"([A-Z]+\s?[A-Z]+[^a-z0-9\W])",text)
    

    Capture A to Z repetitions if there are no trailing lowercase or none-alphabet character.

提交回复
热议问题