Regular Expressions 101

Community Patterns

Localhost/private ip origin check

1

Regular Expression
PCRE (PHP <7.3)

/
^(https?:\/\/)?(localhost|lvh\.me|::1?|fe80::1|((::f{4}:)?(1(0|27)\.\d{1,3}|172\.(1[6-9]|2\d|3[01])|192\.168)\.\d{1,3}\.\d{1,3}))(:\d{1,5})?
/
g

Description

Used by CORS to check for localhost/private IP origins Check out the unit tests at /r/2Ofume/1/tests

Submitted by ngokimphu - 7 years ago