juli1234
juli1234

Reputation: 97

Match regex with Uppercase

I need to match string that starts with uppercase like A, BBB, C, Cela, BLE.

Just the upper case is important.

Trying out I reach this result

\^[A-Z]\w+\gm

but the thing is I'm getting the correct result but not catch just a single string like A, B, C.

what could it be?

thank you!

Upvotes: 2

Views: 50

Answers (2)

Jan
Jan

Reputation: 43199

You need another quantifier:

\^[A-Z]\w*\gm
#       ^^^

The star (*) means "zero or more of the thing in front".

Upvotes: 3

CAustin
CAustin

Reputation: 4614

You were very close to the right solution. The problem is that your pattern will only match strings with 2 or more characters due to the + quantifier after the \w. Instead, use * to match any number of word characters following the initial capital letter.

\^[A-Z]\w*\gm

Upvotes: 3

Related Questions