Skip to content

Instantly share code, notes, and snippets.

@JeffJacobson
Last active October 2, 2015 12:28
Show Gist options
  • Save JeffJacobson/2243518 to your computer and use it in GitHub Desktop.
Save JeffJacobson/2243518 to your computer and use it in GitHub Desktop.
Regular expression that matches a WA state route ID
// This RegEx should match any valid state route identifier.
var _SR_REGEX = /^(\d{3})(?:((?:AR)|(?:C[DI])|(?:C[O])|(?:F[DI])|(?:LX)|(?:[PQRS][\dU])|(?:RL)|(?:SP)|(?:TB)|(?:TR)|(?:PR)|(?:F[ST])|(?:ML))([A-Z0-9]{0,6}))?$/i;
/*
==RRTs (Related Roadway Type)==
AR Alternate Route
CD Collector Distributor (Dec)
CI Collector Distributor (Inc)
CO Couplet
FI Frontage Road (Inc)
FD Frontage Road (Dec)
LX Crossroad within Interchange
RL Reversible Lane
SP Spur
TB Transitional Turnback
TR Temporary Route
PR Proposed Route
===Ramps===
P1 - P9 Off Ramp (Inc)
PU Extension of P ramp
Q1 - Q9 On Ramp (Inc)
QU Extension of Q ramp
R1 - R9 Off Ramp (Dec)
RU Extension of R ramp
S1 - S9 On Ramp (Dec)
SU Extension of S ramp
==Ferries==
FS Ferry Ship (Boat)
FT Ferry Terminal
*/
// Setup a validation method for state routes.
$.validator.addMethod("waroute", function(value, element) {
return _SR_REGEX.test(value);
});
"""This module contains regular expressions for use with state route identifiers.
"""
import re
routeIdRe = re.compile(r"(?P<SR>\d{3})(?:(?P<RRT>[\w1-9]{2})(?P<RRQ>\w{0,6}))?", re.IGNORECASE)
# This re will only match the ID if it is that of a route.
rampRe = re.compile(r"(?P<SR>\d{3})(?:(?P<RRT>(?:C[ID])|(?:[PQRS][U1-9]))(?P<RRQ>\w{0,6}))", re.IGNORECASE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment