JavaScript / ECMAScript

Slug (Unicode Letters Allowed) in JS

Validate URL slugs allowing Unicode letters (`café-rénové`), as supported by Next.js i18n routing.

Try it in the JS tester →

Pattern

regexJS
^[\p{L}\p{N}]+(?:-[\p{L}\p{N}]+)*$   (flags: u)

JavaScript / ECMAScript code

jsJavaScript
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).

How the pattern works

[\p{L}\p{N}]+ matches one or more Unicode letters or numbers (so `café` and `東京` are valid). (?:-[\p{L}\p{N}]+)* allows additional hyphen-separated segments. The u flag is REQUIRED in JavaScript for \p{} property escapes; Python's stdlib `re` doesn't support \p{} (use \w with Unicode flag, or the `regex` package); Go RE2 has its own \p{...} support.

Examples

Input

hello-world

Matches

  • hello-world

Input

café-rénové

Matches

  • café-rénové

Input

trailing-

No match

Same pattern, other engines

← Back to Slug (Unicode Letters Allowed) overview (all engines)