I have come across regular expressions for different problems but I could not find out regex s to balance characters in a string.
I came across a problem, to find if a string is balanced.
ex: aabbccdd
is a balanced one, as a characters are repeated in even numbers
but aabbccddd
is not a balanced one since ddd
is repeated in odd number mode. This is applicable for all characters give an input not to specific a,b,c and d
. If i give input as 12344321
or 123454321
, it should return balanced and unbalanced result respectively.
How to find the balance using regex. What type of regular expression we should use to find if the string is balanced?
Edit:
I tried to find solution using regex only as the problem demands answer in regex pattern. I would implemented using any other solution if regex was not mentioned explicitly