-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
  • 373
  • 6
  • 17

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
  • 17,850
  • 2
  • 16
  • 35