Community Patterns

Community Library Entry

1

Regular Expression
Created·2017-06-01 17:10
Flavor·PCRE (Legacy)

/
^(?![0-9-]+$)(?:[a-z]{2,}-?|[0-9]-?)+(?<!-)$
/
gm
Open regex in editor

Description

This slug regex is optimized using strictly my own opinions.

Slugs:

Should be english, alphanumeric phrases separated with a single dash. Should not contain single alpha character between dashes. Should not be comprised of just numbers and dashes. Should not begin with a number or a dash. Should not end with a dash.

2+ alpha character lookup increases expression speed greatly over allowing 1+ alpha lookups, 3+ improves it more although marginally.)

Submitted by Jordon Baade