I am trying to find a regex that matches if the string contains two different characters or groups which are repeated exactly the same number of times, where that number is unspecified, it can be anything reasonable within the range of positive numbers. So, for instance, this regex should match 'aabbcc'
, but not aabbccc
. It should match only if both a
and c
are repeated the same number of times.
Obviously ,if I try 'a+[^ac]*c+
, it will match if the string contains any number of repetitions of a
and c
, starting from one. If I needed both of the characters to be repeated a specific number of time, then 'a{n}[^ac]*c{n}'
could work, where n
represents the number of repetitions. but neither of them works for me, because I need this regex to match only if both of them are repeated exactly the same number of times, where the number of repetitions isn't specified. Thanks.