Regular Expressions 101

Community Patterns

123...6

Replace anything not a letter or a hyphen

0

Regular Expression
PCRE2 (PHP >=7.3)

/
[^a-zA-Z0-9-]
/
g

Description

Make folder/url safe

use with eg sed:

echo 'My fancy $thing' | sed 's/[^a-zA-Z0-9-]/-/g'

results in My-fancy--thing

Submitted by anonymous - 2 years ago