Question: Hello guys I need to find a regular expression that takes strings with two sets of 11 only
from a set {0,1,2}

```
0011110000          match it only has two sets
0010001001100       does not match (only has one set)
0000011000110011    does not match (it has three sets)
00                  does not match (it has no set
0001100000110001    match it only has two sets

```

This is what I've done so far

```
([^1]|1(0|2|3)(0|2|3)*)*11([^1]|1(0|2|3)(0|2|3)*)*11([^1]|1(0|2|3)(0|2|3)*|1$)*
                                                     --------------------------

```

I think what I'm missing is that I need to make sure the underlined section of the above regular expression has to make sure there is no more "11" left in the string, and I don't think that section is working correctly.

Answer: 
If this is not homework, then I would suggest avoiding a regex and going with a regular function (shown here is JavaScript):

```
function hasTwoElevensOnly(s) {
    var first = s.indexOf("11");
    if (first < 0) return false;
    var second = s.indexOf("11", first + 2);
    if (second < 0) return false;
    return s.indexOf("11", second + 2) < 0;
}

```

Code here: <http://jsfiddle.net/8FMRH/>

```
function hasTwoElevensOnly(s) {
    return /^((0|1(?!1)|2)*?11(0|1(?!1)|2)*?){2}$/.test(s);
}

```

If a regex is required,

COde here: <http://jsfiddle.net/PAARn/1/>
There may be a simpler way, but starting with your approach, this seems to work on the sample data provided:

```
/^([^1]|1[023])*11([^1]|1[023])*11((?<!11)|1[023]|[023]|(?<=[023])1)*$/

```

Using lookbehind.