rspisarski
10/30/2019 - 6:12 PM

Regex

CHARACTER INTERPRETATION
^	        Match only if the characters following are at the beginning
$	        Match only if the characters before are at the end
?	        The character just before this is optional
(?i)	    All following characters are case-insensitive
.	        Any 1 character
*	        Match the previous character 0 or more times
+	        Match the previous 1 or more times
(x)	      Capture group. The characters inside are called by a variable later. Variables are numerical such as $1
.*	      A wildcard; any letter, word or phrase
.+	      Similar to a wildcard but requires at least 1 character be present to continue
(?!)	    Negative lookahead, the following characters are excluded
\	        Escape reserved character so it functions as alphanumeric instead, goes just before each reserved character
Interpretation	                                                            Source RegEx	                  Destination
Redirect from page1 to page2	                                              ^/page1/?$	                    https://example.com/page2/?
Redirect a path but not a page	                                            ^/old/page/?$	                  https://example.com/new/page/?$
Redirect anything in path to a new path, includes the path	                ^/old/(.*)                      https://example.com/new/$1
Redirect anything in path to a new path, but not the path	                  ^/old/(.+)	                    https://example.com/new/$1
Wildcard redirect to change the second directory and the page	              ^/old/(.+)/diff/(.+)	          https://example.com/new/$1/other/$2
Redirect a static asset, such as html	                                      ^/old/page\.html	              https://example.com/new/page.html
^(portfolio/).	/$1

ex. /portfolio/winter-containers/ -> /portfolio/