• Common Regex Redirects

    Add this to your web design tool box. This is a must have a for bootstrap web designers.

    • ^ – Match only if the Following is at the Beginning of the Line
    • $ – Match only if the Previous is at the End of the Line
    • ? – Match the Previous 0 or 1 times (makes it optional)
    • . – Match any Single Character
    • * – Match the Previous 0 or More Times
    • + – Match the Previous 1 or More Times
    • (x) – Matches x and Remembers the match to be called using $1
    • (?:x) – Matches x but does Not remember the match
    • x(?=y) – Matches x Only if it is followed by y
    • x(?!y) – Matches x only if it is NOT followed by y
    • x|y – Matches x or y
    • [xyz] – Matches any character enclosed in the Brackets. Note: This matches X, or Y, or Z; it doesn’t match the string “xyz”.
    • [^xyz] – Matches any character Except for those listed in the Brackets.
    • \ – “Escape” special characters. Thus \? literally matches ? not the Syntax Rule of “previous is option”.
    • \d \w \s – Matches and Digit (number), Alphabetic Character (letter) or White Space (space bar) respectfully.
    • \D \W \S – Matches everything But a Digit, Character, or White Space respectfully.

    Examples:

    Purpose

    Example formatting

    Include an entire directory but nothing beneath it

    http://www.yourdomain.com/shop/

    ^/shop/[^/]*$ **

    Include all subdirectories

    http://www.yourdomain.com/shop/*

    ^/shop/.*

    Include a single file

    http://www.yourdomain.com/shop.php

    ^/shop\.php

    Include any file of a specific type

    ^/shop/.*\.php – any php file

    Include everything that contains a specific phrase

    http://www.yourdomain.com/*shop*

    ^/shop