Quantcast
Channel: CodeProject Latest postings for Regular Expressions
Viewing all articles
Browse latest Browse all 224

Match if token exists only power of n times; Match if length of string is power of n

$
0
0
Hi, I was trying to make a regex that matches only if x is present power of 2 times (n=2). Asked otherwise, make a regex that matches if the length of the string is the power of 2 where the only character in the string is x in this case.

So for example,

xx (2), xxxx (4), xxxxxxxx (8) should match but xxx (3), xxxxxx (6) should not match.

Besides this, I also have a query on the regex I was trying to make:

^((xx)*){2}$


to match xx, xxxx and not xxxxxx but this matches the later (see here). From the debugger also, I cannot understand why last 2 x in 6 x matches with the inner group when we have {2} outside.

Viewing all articles
Browse latest Browse all 224

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>