0

Long sentences are long -- false

Long words are long -- true

Check to see if no word in this string is longer than 6 characters in a regex.

Most answers I've found online talk about checking the string length or a single word length.

  • 1
    As any other similar question it must come with a formal definition what a term "word" precisely means. – zerkms Nov 13 '19 at 23:22
  • You don't need regex for this: `s.split(' ').some((w) => w.length > 6)` where `s` is the string you're testing against. – ctwheels Nov 14 '19 at 02:42
  • 1
    The answer marked as duplicate works for [tag:regex] tagged answers, but this can also be accomplished without regex (in javascript alone); unless a [tag:javascript] tagged question exists for the same (and it's added to the list of duplicates for this question), I think this should be reopened. – ctwheels Nov 14 '19 at 02:45

2 Answers2

1

What Tallboy said, but with a shorter Regex:

\S{6,}

Test Here

My Regex: 37 steps

Tallboy's Regex: 120 steps

maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37
0

It's probably easier to see if theres any words more than 6 and then reverse it with !

!/(^| )\w{6,}( |$)/.test("Long sentences are long")

!/(^| )\w{6,}( |$)/.test("Long words are long")
Tallboy
  • 12,847
  • 13
  • 82
  • 173