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

Regex match words C#

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):

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

True

False

Enter a text in the input above to see the result

Example code in C#:

using System.Text.RegularExpressions;
using System.Linq;
using System;
                    
public class Program
{
    public static void Main()
    {
        // Validate words
        Regex validateWordRegex = new Regex("^\\b(?:\\w|-)+\\b$");
        Console.WriteLine(validateWordRegex.IsMatch("word"));  // prints True
        
        // Extract words from a string
        Regex extractWordsRegex = new Regex("\\b(?:\\w|-)+\\b");
        string [] extracted = extractWordsRegex.Matches("Hello, world!")
            .Cast<Match>()
            .Select(m => m.Value) 
            .ToArray(); 
        Console.WriteLine(String.Join(",", extracted)); // prints 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