-1

I have /^\w+( \w+)*$/

It tests for one space between words, and no leading or trailing spaces.

However, it fails on an edge case where it is passed just the blank string "

I have tried:

/^\w"+( \w+)*$/ 
/^\w\"+( \w+)*$/
/^\w|"+( \w+)*$/

but then it fails my other tests.

Any thoughts are appreciated! Thanks!

Bohemian
  • 412,405
  • 93
  • 575
  • 722
Aly Hoop
  • 115
  • 9

1 Answers1

0

You can just add an alternation for the blank:

^$|^\w+( \w+)*$

See live demo.

IMHO it's easy to read and understand.

Bohemian
  • 412,405
  • 93
  • 575
  • 722