-1

Consider the following strings which would match:

  • HELLO WORLD HOW ARE YOU?
  • HELLO world HOW are YOU?
  • I am a SERIES OF WORDS that are capital
  • I am INVALID.

While these would not match:

  • Hello TV // (tv is not a word)
  • Come to my BBQ at my 1200 SQ.FT House.

The rule is very simple: No all capital words. (abbreviations are fine, words are not)

Currently I have:

^(?!.*\b[A-Z]{2,}\b).*$

this is the closest question but it is almost opposite of what I am trying to do.

I am not good with regex at all, I have tried various online tools and this is as close as I got. I believe the issue lies with the fact it should be something like \w or \W as I want words, not individual characters and not abbreviations like TV, BBQ, SQ.FT and so on, they have to be full on words as indicated above.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
TheWebs
  • 12,470
  • 30
  • 107
  • 211
  • You aren't going to be able to this with just regex. You are going to need a list of valid words to compare your strings to. `\w` and `\W` match word characters (or the inverse), but do not differentiate between actual words and not. – Maximilian Ballard Jan 26 '23 at 02:50

1 Answers1

0

Regular Expressions on their own cannot do this. You would need a separate dictionary with a list of all words that you do not want to be matched, then rule them out afterwards.

  • 2
    Yup, you could also store the words that need to be matched (easier to achieve, though the list would still be enormous) –  Jan 26 '23 at 02:59