Reputation: 11
I am looking for a regex string (to use in GA) that identifys entries that start with words in full capitals.
For example to include:
but exclude:
I have tried to use: ^[A-Z]{5,25}
Any ideas?
Upvotes: 1
Views: 135
Reputation: 41838
To match a string that starts with an upper-case word, use:
^[A-Z]+\b.*
If you want to exclude particular upper-case words at the start of the string, for instance TOM
and JERRY
, modify it to:
^(?!(?:TOM|JERRY)\b)[A-Z]+\b.*
Explanation
^
anchor asserts that we are at the beginning of the string[A-Z]+
matches upper-case letters\b
is a word boundary that matches a position where one side is a letter, and the other side is not a letter (for instance a space character, or the beginning of the string).*
matches any chars to the end of the stringFor the second one, (?!(?:TOM|JERRY)\b)
is a negative lookahead that asserts that what follows is not TOM
or JERRY
, followed by a boundary.
Upvotes: 1