Catch some words only

Question:

I have a paragraph (multiple sentences) and I want to catch all of the capitalised words in each sentence, except for the first word, even tough it is capitalised.

str = "He is a Good boy. When he sings Bob wants to listen. Bravo!"

Expected output:

>>> Good, Bob
Asked By: Norjadi

||

Answers:

import re

string = "He is a Good boy. When he sings Bob wants to listen. Bravo!"

print([i.strip() for i in re.findall(r'b [A-Z][a-zA-Z]*b',string)])

#output: ['Good', 'Bob']

strip() is for getting rid of white space
b [A-Z]' – this part takes all not first capital letters in a word that not first in a sentence
[a-zA-Z]*b' – this part takes any letters after that firs capital letter

Answered By: Dmitriy Neledva
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.