[Solved] Find a singular word that has a capital letter [closed]


The simple answer:

(?!^)\b[A-Z]\w*

It matches any capitalized word that isn’t at the beginning of the line (checked using a negative look-ahead and a word boundary).

See it here at regex101.

But your requirements are sketchy…

John and I are good friends.

would return I. Is that really what you want?

And it’ll only work for the first sentence on a row. Also a line starting with a non character will fail. E.g

-I like John, she said.

“This is a quote.”

Check out this extended regex101.

solved Find a singular word that has a capital letter [closed]