{"id":111837,"date":"2020-04-21T12:54:29","date_gmt":"2020-04-21T12:54:29","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=7746"},"modified":"2020-04-21T12:54:29","modified_gmt":"2020-04-21T12:54:29","slug":"the-dot-character-in-a-character-set-what-does-it-match","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2020\/04\/21\/the-dot-character-in-a-character-set-what-does-it-match\/","title":{"rendered":"The Dot Character in a Character Set \u2013 What Does It Match?"},"content":{"rendered":"<p>Given is the following regular expression:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">regex = '[a-z.]+'<\/pre>\n<p>Note the <a href=\"https:\/\/blog.finxter.com\/python-re-dot\/\" target=\"_blank\" rel=\"noreferrer noopener\">dot character<\/a> inside the character set. As you may know, the dot metacharacter matches an arbitrary character if it is used outside a <a href=\"https:\/\/blog.finxter.com\/python-character-set-regex-tutorial\/\" target=\"_blank\" rel=\"noreferrer noopener\">character set<\/a>. <\/p>\n<p><strong>But what does it match if you place the dot character <a href=\"https:\/\/blog.finxter.com\/does-the-dot-regex-match-whitespace-characters-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">inside a regex character set<\/a>?<\/strong><\/p>\n<p><strong>The answer is that the dot inside the character set matches the dot symbol&#8212;and not an arbitrary character. The reason is that the character set removes the special meaning of the dot symbol. <\/strong><\/p>\n<p>Here&#8217;s a simple example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import re regex = '[a-z.]+' text_1 = 'hello.world'\ntext_2 = 'HELLO.WORLD' print(re.match(regex, text_1))\n# &lt;re.Match object; span=(0, 11), match='hello.world'> print(re.match(regex, text_2))\n# None<\/pre>\n<p>The first text will be matched in both cases (the dot character matches an arbitrary character or the dot symbol). <\/p>\n<p>But the second text will only match if the dot has the meaning: <em>&#8220;match an arbitrary character&#8221;<\/em>. Otherwise, the character set cannot match the text. <\/p>\n<p>As the result is None, the text could not have been matched. <strong>This proves that the dot metacharacter loses its special meaning inside a character set.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Given is the following regular expression: regex = &#8216;[a-z.]+&#8217; Note the dot character inside the character set. As you may know, the dot metacharacter matches an arbitrary character if it is used outside a character set. But what does it match if you place the dot character inside a regex character set? The answer is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-111837","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/111837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=111837"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/111837\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=111837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=111837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=111837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}