Python (re)

Slug (Unicode Letters Allowed) in PY

Python (re) can't run this pattern out of the box.

Try it in the PY tester →

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

Workaround

Replace `\p{L}` with explicit Unicode ranges, or drop the `u` flag if you only need ASCII matching.

Pattern

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

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)