EasyRegex Logo
EasyRegex
Nouveau

Match Only Letters and Spaces in JavaScript

javascript

Expression Régulière

^[a-zA-Z\s]+$
Copier
Avez-vous des Retours ?

Explication

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

Exemple d'Utilisation

const regex = /^[a-zA-Z\s]+/; 
const str = 'Hello World'; 
console.log(regex.test(str)); // Output: true
Copier
Testez l'expression

Expressions Régulières Similaires