I try to scan a text and replace every \command{<more_text>} with <more_test> but can also contain }. I assume that the curly brackets in <more_text> are balanced.
Hence, I guess I could probably write a script from scratch that scans every character and checks if it is \ if yes then if the next is c and o and so on until I am at {. Then I would add +1 to a counter if I find { and -1 if I find } and I stop if my counter is negative.
However, I guess there are already more sophisticated solutions for this problem. I was thinking about regex, but I could not find a way to make the pattern detect the nested curly brackets. There are several question (and solutions) about this on this website, but none of them gave me a clue how to adjust them for my problem, since it is not really a recursion. Chat GPT was also only hallucinating answers, at least with regex.
I don't necessarily need to use regex. I am fine with something that works, preferable with emacs or python3.
Test strings that should be detected
The following text
some text \command{here more text \othercommand{dummy {text} lala} further text {dummy text 2} and done}
should be converted into
some text here more text \othercommand{dummy {text} lala} further text {dummy text 2} and done
This code handles all strings as you expect.
How it works:
In test strings, you need to remove the substring "\command{" and the final character "}".
(\\command\{)(\}{1}$)|(or)and get -
(\\command\{)|(\}{1}$)That's it, the template is ready to use!
Check it out on regex101.com