Slug (Unicode Letters Allowed)
Validate URL slugs allowing Unicode letters (`café-rénové`), as supported by Next.js i18n routing.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("^[\\p{L}\\p{N}]+(?:-[\\p{L}\\p{N}]+)*$", "u");
const input = "hello-world";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Why it doesn't work in PY
CPython's stdlib `re` doesn't support `\p{...}` Unicode property escapes (those need the third-party `regex` package).
Approach
Replace `\p{L}` with explicit Unicode ranges, or drop the `u` flag if you only need ASCII matching.
Read the full guide →Workaround code in Python (re)
# Option A: install the third-party `regex` package which DOES
# support \p{...} property escapes (drop-in replacement for `re`).
#
# pip install regex
import regex
pattern = regex.compile(r'^[\p{L}\p{N}]+(?:-[\p{L}\p{N}]+)*$', regex.UNICODE)
matches = pattern.findall("café-rénové hello-world")
print(matches)
# Option B: stay on stdlib `re` and use explicit Unicode ranges for
# the categories you need. Below covers Latin letters + Latin-1 +
# Latin-Extended (handles café, naïve, résumé, etc.).
import re
pattern = re.compile(
r'[A-Za-z\u00C0-\u024F\u1E00-\u1EFF]+',
re.UNICODE,
)
matches = pattern.findall("café-rénové hello-world")
print(matches)Two paths: install the `regex` package (full \p{} support) or stay on stdlib `re` with explicit Unicode block ranges.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[\p{L}\p{N}]+(?:-[\p{L}\p{N}]+)*$`)
input := `hello-world`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
^[\p{L}\p{N}]+(?:-[\p{L}\p{N}]+)*$ (flags: u)Raw source: ^[\p{L}\p{N}]+(?:-[\p{L}\p{N}]+)*$
How it works
Examples
Input
hello-worldMatches
hello-world
Input
café-rénovéMatches
café-rénové
Input
trailing-No match
—Common use cases
- •i18n slug validation in Next.js routing
- •Content-management systems serving non-Latin markets
- •URL safety enforcement for user-generated content
- •Auto-slug generation guards
Related patterns
URL Slug
WebValidate URL slugs: lowercase letters and digits separated by single hyphens, no leading/trailing hyphens.
HTML5 Color Input Value
WebValidate the value of an HTML5 `<input type="color">` — exactly 6 hex digits with leading hash.
URL Path Segment
WebMatch individual `/segment` parts of a URL path, capturing each one.
URL Query String
WebExtract the query string portion of a URL (everything between `?` and `#` or end-of-string).