Here\'s one for you Regex wizards.
This is for use within Notepad++, i.e. it is entered directly into the search and replace dialog.
I need
You can use this pattern:
(?:[^A-Z]\s+|[^a-zA-Z\s]|\A)\K[A-Z]+\b(?!\s+[A-Z])
I'd use
(?<![[:upper:]]) ([[:upper:]]+) (?!([[:upper:]]| )+)
this will also select anything your locale considers to be uppercase, not just A-Z
I tried that regex and it works for me when I use the 'Mark' feature of the Notepad++ Find/Replace. I'm not sure if you have any other test cases though.
(?:[[:lower:]][^A-Za-z]*|\A)\K\b[[:upper:]]+\b(?=[^A-Za-z]*[[:lower:]]|\Z)
I'm using \A
and \Z
because you mentioned multilines.
regex101 demo (with some explanations there).
Be sure to check 'Match case'.
Before:
After:
EDIT: As per update, to inverse the highlighting, I came up with that one... a bit lengthy:
[^A-Z]+|(?:(?=[A-Z]*[a-z])\b[A-Za-z]+\b)|(?:\b[A-Z]+\b(?=[^a-z]+[A-Z])(?:[^a-z]*[A-Z]+)*)
regex101 demo
I would try
(^|\.\s+|[a-z]\s+)([A-Z]+)(\.|\s+[a-z]|$)
That matches: a period or start-of-line or end of a lowercase word; followed by an uppercase word; followed by a period, end-of-line or start of a lowercase word.
The word itself is matched in group 2. If Notepad++ supports lookaround assertions, you can do this so that the only captured word is the single capitalized word:
(?:^|\.\s+|[a-z]\s+)([A-Z]+)(?:\.|\s+[a-z]|$)
You should check for surrounding characters with negative lookahead and negative lookbehind:
(?<![A-Z]\s)\b[A-Z]+\b(?!\s[A-Z])
Live demo
Notepad++ v6.5.1 & works on multi-line purposes too