LogoReturn to Home RegEx
Integrations
All integrations
AWS API
AWS Lambda
DynamoDB
Oracle
Redshift
Snowflake
GraphQL
Supabase
Twilio
Azure Blob Storage
Slack
SendGrid
Generic HTTP API
AWS S3
Stripe
Microsoft SQL
Salesforce
PostgreSQL
MySQL
MongoDB
HubSpot
Google Sheets
Google BigQuery
Firebase
Airtable
Integrations
About UI Bakery
Log in
Request UI Bakery demo
RegEx library
Email regex
Phone number regex
IP address regex
Date regex
URL regex
Numbers only regex (digits only)
UUID regex
Regex match words
ZIP code regex
GUID regex
Password regex
HTML regex (regex remove html tags)
SSN regex
XML regex
Mac address regex
Street address regex

Regex match words

This regular expression can be used to validate that a given string contains only characters in it or extract two words from a given string.

Discover UI Bakery – an intuitive visual internal tools builder. Try it now!
No items found.
JavaScript
Python
Java
C#
PHP

Simple word match

The regular expression to match only words looks like this (including compound words):

/^\b(?:\w|-)+\b$/
Test it!
/^\b(?:\w|-)+\b$/

True

False

Enter a text in the input above to see the result

Example code in Javascript:

var wordsRegex = /^\b(?:\w|-)+\b$/;
// Validate words
wordsRegex.test('word'); // Returns true
wordsRegex.test('pet-friendly'); // Returns true
wordsRegex.test('not a word'); // Returns false

// Extract words from a string
var wordsRegexG = /\b(?:\w|-)+\b/g;
'Hello, world!'.match(wordsRegexG); // returns ['Hello', 'world']

‍

Test it!

True

False

Enter a text in the input above to see the result

Test it!

True

False

Enter a text in the input above to see the result

Create an internal tool with UI Bakery

Discover UI Bakery – an intuitive visual internal tools builder.

Try it now