You can use this Regex:
(?<!\.)(?:\s([A-Z\u00C0-\u00dd][A-Z\u00C0-\u00dd]*[a-z\u00E0-\u00ff][a-zA-Z\u00C0-\u00ffA-Z]*)|\s(A|O|À)(?=\s|\.))
or
(?<!\.)(?:\s([A-ZÀ-Ý][A-ZÀ-Ý]*[a-zà-ÿ][a-zA-ZÀ-ÿ]*)|\s(A|O|À)(?=\s|\.))
And the demo on Regex101.
However, there is the problem with Given Names, but if you do not use them this Regex can capture what you want.
This Regex captures general words and text in general and not only the example phrase, I suggest in the next questions that post more examples of Regex and that are "proof of errors".
Explanation
1st alternative
(?<!\.)\s([A-Z\u00C0-\u00dd][A-Z\u00C0-\u00dd]*[a-z\u00E0-\u00ff]+[a-z\u00E0-\u00ffA-Z\u00C0-\u00dd]*)
(?<!\.)
- Negative Lookbehind - If there is a character .
before the word, does not capture the string.
\s
- Captures any white space (equal to [\r\n\t\f\v ]
).
([A-Z\u00C0-\u00dd][A-Z\u00C0-\u00dd]*[a-z\u00E0-\u00ff]+[A-Z\u00C0-\u00dd]*)
- Capture Group () - Captures words that are not completely uppercase.
[A-Z\u00C0-\u00dd]
- First capital letter - Corresponds a letter between A-Z and index 192 and 221 of Unicode.
[A-Z\u00C0-\u00dd]*
- The second letter may be uppercase or not - Corresponds zero to infinite letters between A-Z and index 192 and 221 of Unicode.
[a-z\u00E0-\u00ff]
- Lower case letter in word - Matches a letter between a-z and index 224 and 255 from Unicode.
[a-zA-Z\u00C0-\u00ffA-Z]*
- After lowercase, captures lowercase or uppercase letters - Corresponds zero to infinite letters between a-z and between A-Z and index 192 and 255 of Unicode.
Does not capture fully uppercase letters as they can be acronyms.
Or
|
2nd Alternative
In cases with the capital pronouns o, a or crase. Which are letters "alone".
\s(A|O|À)(?=\s|\.)
\s
- Captures any white space (equal to [\r\n\t\f\v ]
).
(A|O|À)
- Capture Group - Capture literally A or O or À.
(?=\s|\.)
- Positive Lookahead - After capture group, a white space is required \s
or |
a point \.
.
var string = "User Not Authenticated. Ok Let’s test. Contact ADM." ; .. I made a change and it didn’t work out.
– Marco Souza
@Marconciliosouza Truth. I reread the question and it seemed to me that when there is some point in the middle, the first word should keep the caps. Blz, I’ll try to fix that in the answer.
– Sam
@Marconciliosouza I got it with a simpler regex. I did an Edit in the reply.
– Sam
@danieltakeshi I’ve updated the Edit of the answer. I think you’re right. Obg!
– Sam