What are Regular Expressions?

A Regular Expression, REGEX or REGEXP for short, is a special text string for describing a search pattern.


Regex Tester

AThis regex tester can help you build regular expressions. Make sure 'javascript' is selected in the menu on the left.


Wildcard examples (where * can be anything)

Target: www.example.com/pages/*

HTML
^(http|https):\/\/www.example.com\/pages\/.*$


Target: www.example.com/pages/*/article/


HTML
^(http|https):\/\/www.example.com\/pages\/[^\/]+\/article\/$


Target: www.example.com/user/<user_id>/profile/(numeric user_id)


HTML
^(http|https):\/\/www.example.com\/user\/[0-9]+\/profile\/$



Wildcard excluding a certain pattern

Target: All pages which match the pattern but do not include the word "article" or "post" www.example.com/pages/*/subpage/


HTML
^(http|https):\/\/www.example.com\/pages\/(?!article|post)[^\/]+\/subpage\/$



Excluding certain words or patterns in a URL

Target: All pages which do not include "/somepage" and "/someotherpage"


HTML
^((?!\/somepage|\/someotherpage).)*$


Target: Pages which include the word "page" and do not include "somepage":


HTML
(?=.*page.*)(?!.*otherpage).*



Multiple pages which don't follow any pattern

Target these three pages:

www.example.com/pages/article-one/details/
www.example.com/pages/some-random-word/details/
www.example.com/pages/another-post/details/


HTML
^(http|https):\/\/www.example.com\/pages\/(article-one|some-random-word|another-post)\/details\/$