正则表达式/ 2相同字母/ PHP

Hey im looking for resolution to my problem at PHP. How to create regular expression which will check that I get two of the same letter from range [a-c].No matter in what order. Just about checking whether there are exactly 2.

For example i used it but it doesnt work as I want.

/a{2}b{2}c{2}/

As your last comment stated, I think you are looking for this:

^(?:([abc])\1)*$

Explaining:

^                # from start
(?:              # group without saving
    ([abc])          # group saving in $1 one of: 'a', 'b', or 'c'
    \1               # the same character saved in $1
)*               # repeat it as many as possible
$                # till the end

Check live here

Use a back-reference so that it has to match the same character twice.

/([abc])\1/

Regex101 Example

Or, for multiple back-references:

/(a)\1(b)\2(c)\3/

or

/(([abc])\1)*/

(If you just need to literally match "aabbcc" then your regex should be /aabbcc/)