MattC
MattC

Reputation: 59

regex to match all uppercase letters before the first question mark

I am attempting to create a regex that will match all uppercase letters before the first question mark in a URL string:

/foO/baR/?_heLLo=1320957051041105000&_woRld=0

I have tried both the following:

(?<!(\?))([A-Z])
(?<!\?.*?)([A-Z])

The former captures uppercase letters before and after the question mark. The latter captures no uppercase letters. Any insight would be appreciated, thanks.

Upvotes: 2

Views: 2077

Answers (2)

Marcus
Marcus

Reputation: 12586

This regex would do the trick:

[A-Z](?=.*?\?)

See it in action here: http://regexr.com?2v5r0

Upvotes: 2

Mark Byers
Mark Byers

Reputation: 838156

Try this positive lookbehind:

(?<=^[^?]*)[A-Z]

Upvotes: 1

Related Questions