EasyRegex Logo
EasyRegex
Neu

Match Only Letters and Spaces in JavaScript

javascript

Regulärer Ausdruck

^[a-zA-Z\s]+$
Kopieren
Haben Sie Feedback?

Erklärung

This regex pattern matches strings that contain only letters (both uppercase and lowercase) and spaces. ^ asserts the start of the string, [a-zA-Z] matches any letter, \s matches any whitespace character (in this case, space), + allows for one or more occurrences of the previous characters, and $ asserts the end of the string.

javascript

Beispielverwendung

const regex = /^[a-zA-Z\s]+/; 
const str = 'Hello World'; 
console.log(regex.test(str)); // Output: true
Kopieren
Testen Sie den Ausdruck

Ähnliche Reguläre Ausdrücke