{"id":10645,"date":"2022-07-05T13:18:06","date_gmt":"2022-07-05T17:18:06","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=10645"},"modified":"2022-07-05T14:05:54","modified_gmt":"2022-07-05T18:05:54","slug":"a-regular-expression-conundrum","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=10645","title":{"rendered":"A Regular Expression Conundrum"},"content":{"rendered":"<p>Here\u2019s a little quiz to test your regex-fu. Suppose you want to match any of the strings<\/p>\n<ul class=\"org-ul\">\n<li><code>ab,cd<\/code><\/li>\n<li><code>ab-cd<\/code><\/li>\n<li><code>ab.cd<\/code><\/li>\n<\/ul>\n<p>Someone proposes the regex <code>ab[,-.]cd<\/code> but you object that that\u2019s incorrect because the <code>-<\/code> will be treated as specifying the range of characters between <code>,<\/code> and <code>.<\/code>. Oddly, the regex <i>does<\/i> match all three strings. Why is that?<\/p>\n<p>See <a href=\"https:\/\/pboyd.io\/posts\/comma-dash-dot\/\">Paul Boyd\u2019s post<\/a> for the answer.<\/p>\n<p><b>UPDATE<\/b> <span class=\"timestamp-wrapper\"><span class=\"timestamp\">[2022-07-05 Tue 14:04]<\/span><\/span>:<\/p>\n<p>I should have said that the regex matches all three strings and <i>only<\/i> those strings.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here\u2019s a little quiz to test your regex-fu. Suppose you want to match any of the strings ab,cd ab-cd ab.cd Someone proposes the regex ab[,-.]cd but you object that that\u2019s incorrect because the &#8211; will be treated as specifying the &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=10645\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[37],"class_list":["post-10645","post","type-post","status-publish","format-standard","hentry","category-general","tag-tech"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10645"}],"version-history":[{"count":3,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10645\/revisions"}],"predecessor-version":[{"id":10648,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10645\/revisions\/10648"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}