{"id":62,"date":"2009-03-04T09:31:11","date_gmt":"2009-03-04T09:31:11","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=62"},"modified":"2009-03-04T09:31:11","modified_gmt":"2009-03-04T09:31:11","slug":"regular-expression-basics-quick-reference","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/regular-expression-basics-quick-reference","title":{"rendered":"Regular Expression Basics &#8211; Quick Reference"},"content":{"rendered":"<table border=\"0\" cellspacing=\"15\" cellpadding=\"0\" width=\"400px\">\n<tbody>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\"><strong>Characters<\/strong><strong> <\/strong><\/p>\n<p align=\"center\">\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"center\"><strong>Character<\/strong><strong> <\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Description<\/strong><strong> <\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Example<\/strong><strong> <\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Any character except [\\^$.|?*+()<\/td>\n<td valign=\"top\">All characters except the listed special characters match a   single instance of themselves. { and } are literal characters, unless they&#8217;re   part of a valid regular expression token (e.g. the {n} quantifier).<\/td>\n<td valign=\"top\">a matches a<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\ (backslash) followed by any of [\\^$.|?*+(){}<\/td>\n<td valign=\"top\">A backslash escapes special characters to suppress their special   meaning.<\/td>\n<td valign=\"top\">\\+ matches +<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\Q&#8230;\\E<\/td>\n<td valign=\"top\">Matches the characters between \\Q and \\E literally, suppressing   the meaning of special characters.<\/td>\n<td valign=\"top\">\\Q+-*\/\\E matches +-*\/<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\xFF where FF are 2 hexadecimal digits<\/td>\n<td valign=\"top\">Matches the character with the specified ASCII\/ANSI value, which   depends on the code page used. Can be used in character classes.<\/td>\n<td valign=\"top\">\\xA9 matches \u00a9 when using the Latin-1 code page.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\n, \\r and \\t<\/td>\n<td valign=\"top\">Match an LF character, CR character and a tab character   respectively. Can be used in character classes.<\/td>\n<td valign=\"top\">\\r\\n matches a DOS\/Windows CRLF line break.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\a, \\e, \\f and \\v<\/td>\n<td valign=\"top\">Match a bell character (\\x07), escape character (\\x1B), form   feed (\\x0C) and vertical tab (\\x0B) respectively. Can be used in character   classes.<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\cA through \\cZ<\/td>\n<td valign=\"top\">Match an ASCII character Control+A through Control+Z, equivalent   to \\x01 through \\x1A. Can be used in character classes.<\/td>\n<td valign=\"top\">\\cM\\cJ matches a DOS\/Windows CRLF line break.<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\"><strong>Character   Classes or Character Sets [abc]<\/strong><\/p>\n<p align=\"center\">\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"center\"><strong>Character<\/strong><strong> <\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Description<\/strong><strong> <\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Example<\/strong><strong> <\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">[ (opening square bracket)<\/td>\n<td valign=\"top\">Starts a character class. A character class matches a single   character out of all the possibilities offered by the character class. Inside   a character class, different rules apply. The rules in this section are only   valid inside character classes. The rules outside this section are not valid   in character classes, except \\n, \\r, \\t and \\xFF<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Any character except ^-]\\ add that character to the possible   matches for the character class.<\/td>\n<td valign=\"top\">All characters except the listed special characters.<\/td>\n<td valign=\"top\">[abc] matches a, b or c<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\ (backslash) followed by any of ^-]\\<\/td>\n<td valign=\"top\">A backslash escapes special characters to suppress their special   meaning.<\/td>\n<td valign=\"top\">[\\^\\]] matches ^ or ]<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">&#8211; (hyphen) except immediately after the opening [<\/td>\n<td valign=\"top\">Specifies a range of characters. (Specifies a hyphen if placed   immediately after the opening [)<\/td>\n<td valign=\"top\">[a-zA-Z0-9] matches any letter or digit<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">^ (caret) immediately after the opening [<\/td>\n<td valign=\"top\">Negates the character class, causing it to match a single   character\u00a0<em>not<\/em> listed in the character class.   (Specifies a caret if placed anywhere except after the opening [)<\/td>\n<td valign=\"top\">[^a-d] matches x (any character except a, b, c or d)<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\d, \\w and \\s<\/td>\n<td valign=\"top\">Shorthand character classes matching digits 0-9, word characters   (letters and digits) and whitespace respectively. Can be used inside and   outside character classes.<\/td>\n<td valign=\"top\">[\\d\\s] matches a character that is a digit or whitespace<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\D, \\W and \\S<\/td>\n<td valign=\"top\">Negated versions of the above. Should be used only outside   character classes. (Can be used inside, but that is confusing.)<\/td>\n<td valign=\"top\">\\D matches a character that is not a digit<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">[\\b]<\/td>\n<td valign=\"top\">Inside a character class, \\b is a backspace character.<\/td>\n<td valign=\"top\">[\\b\\t] matches a backspace or tab character<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\"><strong>Dot<\/strong><\/p>\n<p align=\"center\">\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"center\"><strong>Character<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Description<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Example<\/strong><strong><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">. (dot)<\/td>\n<td valign=\"top\">Matches any single character except line break characters \\r and   \\n. Most regex flavors have an option to make the dot match line break   characters too.<\/td>\n<td valign=\"top\">. matches x or (almost) any other character<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\"><strong>Anchors<\/strong><\/p>\n<p align=\"center\">\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"center\"><strong>Character<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Description<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Example<\/strong><strong><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">^ (caret)<\/td>\n<td valign=\"top\">Matches at the start of the string the regex pattern is applied   to. Matches a position rather than a character. Most regex flavors have an   option to make the caret match after line breaks (i.e. at the start of a line   in a file) as well.<\/td>\n<td valign=\"top\">^. matches a in abc\\ndef. Also matches d in   &#8220;multi-line&#8221; mode.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">$ (dollar)<\/td>\n<td valign=\"top\">Matches at the end of the string the regex pattern is applied   to. Matches a position rather than a character. Most regex flavors have an   option to make the dollar match before line breaks (i.e. at the end of a line   in a file) as well. Also matches before the very last line break if the   string ends with a line break.<\/td>\n<td valign=\"top\">.$ matches f in abc\\ndef. Also matches c in   &#8220;multi-line&#8221; mode.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\A<\/td>\n<td valign=\"top\">Matches at the start of the string the regex pattern is applied   to. Matches a position rather than a character. Never matches after line   breaks.<\/td>\n<td valign=\"top\">\\A. matches a in abc<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\Z<\/td>\n<td valign=\"top\">Matches at the end of the string the regex pattern is applied   to. Matches a position rather than a character. Never matches before line   breaks, except for the very last line break if the string ends with a line   break.<\/td>\n<td valign=\"top\">.\\Z matches f in abc\\ndef<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\z<\/td>\n<td valign=\"top\">Matches at the end of the string the regex pattern is applied   to. Matches a position rather than a character. Never matches before line   breaks.<\/td>\n<td valign=\"top\">.\\z matches f in abc\\ndef<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\"><strong>Word   Boundaries<\/strong><\/p>\n<p align=\"center\">\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"center\"><strong>Character<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Description<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Example<\/strong><strong><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\b<\/td>\n<td valign=\"top\">Matches at the position between a word character (anything   matched by \\w) and a non-word character (anything matched by [^\\w] or \\W) as   well as at the start and\/or end of the string if the first and\/or last   characters in the string are word characters.<\/td>\n<td valign=\"top\">.\\b matches c in abc<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\\B<\/td>\n<td valign=\"top\">Matches at the position between two word characters (i.e the   position between \\w\\w) as well as at the position between two non-word   characters (i.e. \\W\\W).<\/td>\n<td valign=\"top\">\\B.\\B matches b in abc<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\"><strong>Alternation<\/strong><\/p>\n<p align=\"center\">\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"center\"><strong>Character<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Description<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Example<\/strong><strong><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">| (pipe)<\/td>\n<td valign=\"top\">Causes the regex engine to match either the part on the left   side, or the part on the right side. Can be strung together into a series of   options.<\/td>\n<td valign=\"top\">abc|def|xyz matches abc, def or xyz<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">| (pipe)<\/td>\n<td valign=\"top\">The pipe has the lowest precedence of all operators. Use   grouping to alternate only part of the regular expression.<\/td>\n<td valign=\"top\">abc(def|xyz) matches abcdef or abcxyz<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\"><strong>Quantifiers<\/strong><\/p>\n<p align=\"center\">\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"center\"><strong>Character<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Description<\/strong><strong><\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Example<\/strong><strong><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">? (question mark)<\/td>\n<td valign=\"top\">Makes the preceding item optional. Greedy, so the optional item   is included in the match if possible.<\/td>\n<td valign=\"top\">abc? matches ab or abc<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">??<\/td>\n<td valign=\"top\">Makes the preceding item optional. Lazy, so the optional item is   excluded in the match if possible. This construct is often excluded from   documentation because of its limited use.<\/td>\n<td valign=\"top\">abc?? matches ab or abc<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">* (star)<\/td>\n<td valign=\"top\">Repeats the previous item zero or more times. Greedy, so as many   items as possible will be matched before trying permutations with less   matches of the preceding item, up to the point where the preceding item is   not matched at all.<\/td>\n<td valign=\"top\">&#8220;.*&#8221; matches &#8220;def&#8221; &#8220;ghi&#8221; in abc   &#8220;def&#8221; &#8220;ghi&#8221; jkl<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">*? (lazy star)<\/td>\n<td valign=\"top\">Repeats the previous item zero or more times. Lazy, so the   engine first attempts to skip the previous item, before trying permutations   with ever increasing matches of the preceding item.<\/td>\n<td valign=\"top\">&#8220;.*?&#8221; matches &#8220;def&#8221; in abc &#8220;def&#8221;   &#8220;ghi&#8221; jkl<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">+ (plus)<\/td>\n<td valign=\"top\">Repeats the previous item once or more. Greedy, so as many items   as possible will be matched before trying permutations with less matches of   the preceding item, up to the point where the preceding item is matched only   once.<\/td>\n<td valign=\"top\">&#8220;.+&#8221; matches &#8220;def&#8221; &#8220;ghi&#8221; in abc   &#8220;def&#8221; &#8220;ghi&#8221; jkl<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">+? (lazy plus)<\/td>\n<td valign=\"top\">Repeats the previous item once or more. Lazy, so the engine   first matches the previous item only once, before trying permutations with   ever increasing matches of the preceding item.<\/td>\n<td valign=\"top\">&#8220;.+?&#8221; matches &#8220;def&#8221; in abc &#8220;def&#8221;   &#8220;ghi&#8221; jkl<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">{n} where n is an integer &gt;= 1<\/td>\n<td valign=\"top\">Repeats the previous item exactly n times.<\/td>\n<td valign=\"top\">a{3} matches aaa<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">{n,m} where n &gt;= 0 and m &gt;= n<\/td>\n<td valign=\"top\">Repeats the previous item between n and m times. Greedy, so   repeating m times is tried before reducing the repetition to n times.<\/td>\n<td valign=\"top\">a{2,4} matches aaaa, aaa or aa<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">{n,m}? where n &gt;= 0 and m &gt;= n<\/td>\n<td valign=\"top\">Repeats the previous item between n and m times. Lazy, so   repeating n times is tried before increasing the repetition to m times.<\/td>\n<td valign=\"top\">a{2,4}? matches aa, aaa or aaaa<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">{n,} where n &gt;= 0<\/td>\n<td valign=\"top\">Repeats the previous item at least n times. Greedy, so as many   items as possible will be matched before trying permutations with less   matches of the preceding item, up to the point where the preceding item is   matched only n times.<\/td>\n<td valign=\"top\">a{2,} matches aaaaa in aaaaa<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">{n,}? where n &gt;= 0<\/td>\n<td valign=\"top\">Repeats the previous item n or more times. Lazy, so the engine   first matches the previous item n times, before trying permutations with ever   increasing matches of the preceding item.<\/td>\n<td valign=\"top\">a{2,}? matches aa in aaaaa<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\">source: www.regular-expressions.info<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"Characters Character Description Example Any character except [\\^$.|?*+() All characters except the listed special characters match a single instance of themselves. { and } are literal characters, unless they&#8217;re part&hellip;\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6],"tags":[99,426],"class_list":{"0":"post-62","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-technical","7":"tag-regular-expression","8":"tag-technical"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":0,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}