fork download
  1. import re
  2.  
  3. s = r'''
  4. \newcommand{\commandName1}{This is first command}
  5.  
  6. \newcommand{\commandName2}{This is second command with {} brackets inside
  7. in multiple lines {} {}
  8. }
  9.  
  10. \newcommand{\commandName3}{This is third, last command}
  11. '''
  12.  
  13. print (re.findall(r'(?s)\\newcommand{([^}]+)}{(.+?)}(?=\s*(?:\\newcommand|$))', s))
  14.  
Success #stdin #stdout 0.03s 9620KB
stdin
Standard input is empty
stdout
[('\\commandName1', 'This is first command'), ('\\commandName2', 'This is second command with {} brackets inside\nin multiple lines {} {}\n'), ('\\commandName3', 'This is third, last command')]