Nir Berko
Nir Berko

Reputation: 1426

regex to find uppercase words and lowercase words

I am looking for a regex that can separate string to uppercase words and lowercase words and insert them inside an object (i just need the regex and I can move forward from there). I am trying to build SQL like queries, this is an example:

SEARCH FOR hello AND LOOK AFTER FOR 1 words

and I want to make an object from this, that will become something like this:

{
 SEARCHFOR: 'hello',
 ANDLOOKAFTERFOR: '1 words'
}

I'm terrible at regex so sorry for the question. thanks you all!

Upvotes: 0

Views: 281

Answers (1)

41686d6564
41686d6564

Reputation: 19651

You can use the following regex:

([A-Z\s]+)([a-z0-9\s]+)

Demo.

You can access the uppercase words in the first group, and the lowercase words and numbers in the second group.

Details:

  • ([A-Z\s]+) one or more uppercase letter or whitespace character in a capturing group.
  • ([a-z0-9\s]+) one or more lowercase letter, digit, or whitespace character in a capturing group.

Upvotes: 1

Related Questions