fork download
  1. import re
  2.  
  3. example = ("OPERATOR: Some text with numbers, special characters and linebreaks.\n\n"
  4. "NAME, COMPANY, POSITION: Some text with numbers, special characters and linebreaks.\n"
  5. "NAME: Some text with numbers, special characters and linebreaks.")
  6. r = re.compile(r"^([^a-z\r\n]+):(.*(?:(?!\n[^a-z\r\n]+:)[\r\n].*)*)", flags=re.MULTILINE)
  7. print(re.findall(r, example))
Success #stdin #stdout 0.02s 27728KB
stdin
Standard input is empty
stdout
[('OPERATOR', ' Some text with numbers, special characters and linebreaks.\n'), ('NAME, COMPANY, POSITION', ' Some text with numbers, special characters and linebreaks.'), ('NAME', ' Some text with numbers, special characters and linebreaks.')]