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 Python
Phone number regex Python
IP address regex Python
Date regex Python
URL regex Python
Numbers only regex (digits only) Python
UUID regex Python
Regex match words Python
ZIP code regex Python
GUID regex Python
Password regex Python
HTML regex Python
SSN regex Python
XML regex Python
Mac address regex Python
Street address regex Python

Regex match words Python

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!
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 Python:

# Validate words
words_pattern = "^\\b(?:\\w|-)+\\b$"
re.match(words_pattern, 'word') # Returns Match object
re.match(words_pattern, 'pet-friendly') # Returns Match object
re.match(words_pattern, 'not a word') # Returns None

# Extract words from a string
words_extract_pattern = "\\b(?:\\w|-)+\\b"
re.findall(words_extract_pattern, 'Hello, world!') # 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