i try to get only upper letter in the last of this sentence
abc N°12558 to company ABC DEF GH 123
i want take only ABC DEF GH
i try this, but number in last make problem
(.[A-Z\s]+)*$
i try to get only upper letter in the last of this sentence
abc N°12558 to company ABC DEF GH 123
i want take only ABC DEF GH
i try this, but number in last make problem
(.[A-Z\s]+)*$
You may use this regex with a lookahead:
\b[A-Z]+(?:\s+[A-Z]+)*(?=[^A-Z]*$)
RegEx Details:
\b: Word boundary[A-Z]+: Match a word with 1+ uppercase letters(?:\s+[A-Z]+)*: Match 0 or more space separated uppercase words(?=[^A-Z]*$): Lookahead to assert that we don't have any uppercase letters aheadCheck if this helps you: https://regex101.com/r/RtcacF/1
This regex will only match the upper case letters (1 or more) that are followed with a space or tab.
[A-Z]+\s
if you don't want to keep the space you can wrap it with a group, like this:
([A-Z]+)\s