For reasons beyond the scope here, I'm building a simple bibtex parser. Some bibtex fields are delimited by a single curly brace, while others are delimited by double curly braces. Curly braces are also valid content for the field.
I have a string that I know corresponds to a single field, in the formats:
fieldName1 = {{ content }},\n -> content
fieldName2 = { content },\n -> content
fieldName3 = { {[}content,] },\n -> {[}content,]
With this pattern I can recover the content:
re.compile(r"(?P<name>[\w-]+?)[\s]*=[\s]*({(?P<content>.*)})", flags=re.IGNORECASE|re.DOTALL)
But it will contain { and } if that field uses double braces.
Is there an easier way to remove them than to test [0]=='{' and [-1]=='}'