Regular Expressions 101

Localhost/private ip origin check

Open Workspace
  • PCRE (Legacy)
  • Match
1

Regular Expression

/
^(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