Regular expression to match two numbers that are not equal

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My question was:

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.

What I have till now is: I have to match strings like “P12”, and I’ve done it with this regex:

^P([1-6]{1})([1-6]{1})$

But now my problem is how to match only strings like P12 or P32 where the numbers do not repeat.

Any help or guidance to reading materials will be grateful.

edit:  this is what worked:

^P([1-6]{1})(?!\1)([1-6]{1})$

 The answer, by Ignacio Vazquez-Abrams, was:

Use this:

^P((1[2-6])|(2[13-6])|(3[124-6])|(4[1-356])|(5[1-46])|(6[1-5]))$
Written by Nikola Brežnjak