fork download
  1. import re
  2. text = """SECTION 1. CHAPTER 1. Chapter title. Art. 1.- Lorem ipsum, blah, blah. Art 2.- More meaningless text. Art 3.- A little more text. CHAPTER 2. Another chapter. Art 4.- Lorem ipsum blah, blah, blah. Art. 5.- It's getting boring. SECTION 2. CHAPTER 1. Another chapter in another section. Art. 6.- The last text. SECTION 3. CHAPTER 1. Another chapter in another section. Art. 6.- The last text. SECTION 4. CHAPTER 1. Another chapter in another section. Art. 6.- The last text."""
  3. print(dict(re.findall(r"(SECTION\s+\d+)\.\s*([^S]*(?:S(?!ECTION\s+\d+\.)[^S]*)*)", text)))
  4.  
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
{'SECTION 4': 'CHAPTER 1. Another chapter in another section. Art. 6.- The last text.', 'SECTION 1': "CHAPTER 1. Chapter title. Art. 1.- Lorem ipsum, blah, blah. Art 2.- More meaningless text. Art 3.- A little more text. CHAPTER 2. Another chapter. Art 4.- Lorem ipsum blah, blah, blah. Art. 5.- It's getting boring. ", 'SECTION 2': 'CHAPTER 1. Another chapter in another section. Art. 6.- The last text. ', 'SECTION 3': 'CHAPTER 1. Another chapter in another section. Art. 6.- The last text. '}