<jupyter_start><jupyter_text><jupyter_code>#nested parentheses
import re
inputString = "foo(bar(baz))blim"

split_str = [", ".join(x.split()) for x in re.split(r'[()]',inputString) if x.strip()]
print('split_str:', split_str)<jupyter_output>split_str: ['foo', 'bar', 'baz', 'blim']<jupyter_text>[find matching pattern with regular expression, split and join](https://stackoverflow.com/questions/40552212/find-all-strings-in-nested-brackets)<jupyter_code>def match(string):
    unrefined_match=re.findall('\((\w+)|(\w+)\)', string)
    return [x for i in unrefined_match for x in i if x]

str_in_parentheses = match(inputString)
print('str_in_parentheses:', str_in_parentheses )

def reverseInParentheses(s):
    return eval('"' + s.replace('(', '"+("').replace(')', '")[::-1]+"') + '"')
#test
res = reverseInParentheses(inputString)
print('res:', res)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19750283768444948, 'fraction_numerical': 0.01021566401816118, 'mean_word_length': 7.320754716981132, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '583370', 'license': 'MIT', 'n_tokens_mistral': 344, 'n_tokens_neox': 325, 'n_words': 59, 'path': 'reverseInParentheses.ipynb', 'repo_name': 'maithoi/CodeSignal', 'size': '881'}