Consider a string, s, consisting only of the letters a and b. We say that string s is balanced if both of the following conditions are satisfied:
a and b.a and b differ by at most 1.Your task is to write a regular expression accepting only balanced strings.
Substrings can differ by at most 1 which means that the string must consist of either “ab” or “ba”. Write a regex as such.
Regex_Pattern = r"^((ab)|(ba))*$" # Do not delete 'r'.