Like tried with this sample with no special character:
let x = new RegExp('^[A-Za-z\s0-9]+$'); // with no special char x.test('Hello world'); // should return true x.test('Hello world with something'); // should return true x.test(' Hello world'); // should return false x.test('Hello world '); // should return false x.test('Hello world'); // should return false
const x = /^[a-zA-Z0-9]+(?:\s[a-zA-Z0-9]+)*$/'^[A-Za-z\\s0-9]+$'let x = /^[A-Za-z\s0-9]+$/or a raw string:let x = new RegExp(String.raw`^[A-Za-z\s0-9]+$`)