-2

I am trying to create a regExpr te define if a string contains a % or a whitespace or a combination of the 2.

Example:

'%%%%' ---> true
'%    %%%' ---> true
'test%' ---> false

can someone help?

thx a lot

user3356007
  • 393
  • 1
  • 6
  • 20

1 Answers1

1

You can use this regex,

^[% ]+$

Check this JS code demo,

var arr = ['%%%%','%    %%%','test%']

for(s of arr) {
  console.log(s + ' ---> ' +/^[% ]+$/.test(s));
  }
Pushpesh Kumar Rajwanshi
  • 18,127
  • 2
  • 19
  • 36