DD
DevDash

Regex for kebab-case Word

Regex Pattern

^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$

kebab-case identifier (lowercase with hyphens)

Quick Answer

The regex pattern for kebab-case word is `^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$`. kebab-case identifier (lowercase with hyphens). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
my-component✓ Matches
header-nav✓ Matches
get-user-data✓ Matches
myComponent✗ No match
My-Component✗ No match
single✗ No match
UPPER-CASE✗ No match

Code Examples

javascript

const regex = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/;
const isValid = regex.test(value);

python

import re
pattern = r'^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/', $value)) {
    echo "valid";
}

java

String pattern = "^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.