-1

Currently I'm using regex=/^(\w+\s?)*\s*$/, it's working fine for extra space, but failing for special characters.

Expectation:

  1. regex.test('abcd ghh') => false
  2. regex.test('abcd*') => true
Matteo Guarnerio
  • 720
  • 2
  • 9
  • 26
tabinda
  • 39
  • 1
  • 5
  • 3
    Your regex [matches neither of these strings](https://regex101.com/r/wr3eVx/1). It seems you are using the regex with `g` modifier. Please make sure you have no `g` flag. Also, what are you trying to achieve? It is not clear from the question/title. – Wiktor Stribiżew Apr 12 '19 at 12:55

1 Answers1

0

You will need the last regex pattern of this solution.

[^\s]([ ]{2,})[^\s]

Tim VN
  • 1,183
  • 1
  • 7
  • 19