{"id":1367,"date":"2015-04-07T06:30:40","date_gmt":"2015-04-07T06:30:40","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1367"},"modified":"2015-08-06T12:22:32","modified_gmt":"2015-08-06T12:22:32","slug":"regular-expression-to-match-two-numbers-that-are-not-equal","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/regular-expression-to-match-two-numbers-that-are-not-equal\/","title":{"rendered":"Regular expression to match two numbers that are not equal"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[1367]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/5257685\/regular-expression-to-match-two-numbers-that-are-not-equal\">question<\/a> was:<\/p>\n<p>I was wondering how can I match two digits but which are not the same. So, it would be fine to match 12, but not 11.<\/p>\n<p>What I have till now is: I have to match strings like &#8220;P12&#8221;, and I&#8217;ve done it with this regex:<\/p>\n<pre class=\"lang:default decode:true\">^P([1-6]{1})([1-6]{1})$<\/pre>\n<p>But now my problem is how to match only strings like P12 or P32 where the numbers do not repeat.<\/p>\n<p>Any help or guidance to reading materials will be grateful.<\/p>\n<p>edit: \u00a0this is what worked:<\/p>\n<pre class=\"default prettyprint prettyprinted\" style=\"color: #393318;\"><code><span class=\"pun\" style=\"color: #000000;\">^<\/span><span class=\"pln\" style=\"color: #000000;\">P<\/span><span class=\"pun\" style=\"color: #000000;\">([<\/span><span class=\"lit\" style=\"color: #800000;\">1<\/span><span class=\"pun\" style=\"color: #000000;\">-<\/span><span class=\"lit\" style=\"color: #800000;\">6<\/span><span class=\"pun\" style=\"color: #000000;\">]{<\/span><span class=\"lit\" style=\"color: #800000;\">1<\/span><span class=\"pun\" style=\"color: #000000;\">})(?!<\/span><span class=\"pln\" style=\"color: #000000;\">\\1<\/span><span class=\"pun\" style=\"color: #000000;\">)([<\/span><span class=\"lit\" style=\"color: #800000;\">1<\/span><span class=\"pun\" style=\"color: #000000;\">-<\/span><span class=\"lit\" style=\"color: #800000;\">6<\/span><span class=\"pun\" style=\"color: #000000;\">]{<\/span><span class=\"lit\" style=\"color: #800000;\">1<\/span><span class=\"pun\" style=\"color: #000000;\">})<\/span><span class=\"pln\" style=\"color: #000000;\">$<\/span><\/code><\/pre>\n<p style=\"color: #222222;\">\u00a0The answer, by <a style=\"color: #0c65a5;\" href=\"http:\/\/stackoverflow.com\/users\/20862\/ignacio-vazquez-abrams\">Ignacio Vazquez-Abrams<\/a>,\u00a0was:<\/p>\n<blockquote><p>Use this:<\/p>\n<pre class=\"lang:default decode:true  \">^P((1[2-6])|(2[13-6])|(3[124-6])|(4[1-356])|(5[1-46])|(6[1-5]))$<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts I will will be posting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1367"}],"version-history":[{"count":2,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1367\/revisions"}],"predecessor-version":[{"id":1685,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1367\/revisions\/1685"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}