I am trying to make a regex that will match a number of x
's that is a power of two. I am using JavaScript. I tried this one:
^(x\1?)$
but it doesn't work. Shouldn't the \1
refer to the outer parathesis so it should match xx
, and therefore also xxxx
, etc.?
I tried a simpler one that I thought would match x and xx:
^((x)|(\2{2}))$
but this only matches x
.
What am I doing wrong?