Regular Expressions

Regular expressions use match modifiers to match URL patterns commonly used in the rewriting of urls when using mod_rewrite functionality.  It’s not just specific to mod_write, but used across manage languages and scripting.

Below are the most commonly used regular expression modifiers with a brief explanation of each:

  • A period (.) signifies any character
  • A dollar sign ($) signifies the end of a string match
  • A caret (^) symbol is used to signify the start of a string match (typically when using RewriteRule)
  • A plus sign (+) signifies and applies to the one or more character(s) before it (may be a range)
  • An asterisk (*) signifies zero or more characters before it
  • A question mark (?) signifies zero or only one character preceding it
  • An exclamation mark (!) signifies a negative pattern if at start of string
  • The backslash (\) appears before a period or special character to escape it as a normal character won’t attempt to process it otherwise
  • A pipe (|) signifies or or alternative
  • Parenthesis () signifies group, back referenced group
  • The minus or hyphen (-) signifies a range if used between square brackets
  • Brackets ([]) signify match any contents
  • Curly brackets ({}) signifies minimum to maximum quantifier

For more on regular expressions, I suggest using Regular-Expressions.info or RegExr.com.