I want to use python regex to find the document class in a latex document.
A latex file contains \documentclass{myclass}
somewhere near the top. I want to find myclass
using regex.
This is what I've tried so far:
latex_text = "blank /documentclass{myclass} words, more text /documentclassdoc{11} more words"
s=re.search(r'/documentclass{(?P<class_name>.*)}', latex_text)
It matches: myclass} words, more text /documentclassdoc{11
How can I change it to only match myclass
. It should also stop searching after it finds a match, as the document can get quite long.
I know the file should only have one documentclass, but I want to handle the case where there is more than 1 as well.