smwikipedia
smwikipedia

Reputation: 64453

How to write a regex to capture all the words with capitalized letter except one

How to write a regex to match all the words with capitalized letter, but not match the BackGround in "a.BackGround = 1".

For example,

I have FireFox and Safari. And I set a.BackGround =1

In the above sentence, I want to match FireFox, Safari, I and And, but not BackGround.

Upvotes: 0

Views: 54

Answers (2)

Vasili Syrakis
Vasili Syrakis

Reputation: 9641

I don't know how well this will apply to other situations, but so far this is all the information you have given us.

This will match the words themselves, no need for capture groups, unless you so choose to use them:

(?<=\s|^)[A-Z]\w*

If the match is more complex, or applies to more than just the sample text you gave us, please let me know.

Upvotes: 1

Toto
Toto

Reputation: 91518

Is this sufficient:

(?:^|\s)([A-Z]\S*)

The word is in group 1.

Upvotes: 2

Related Questions