fork download
  1. import re
  2.  
  3. pattern = r"^Rom\. .*(?:\n(?!(?:Rom|Jul)\. ).*)*"
  4.  
  5. allLines = ("Jul. Wilt thou be gone? It is not yet near day. It was the nightingale, and not the lark, That pierc'd the fearful hollow of thine ear. Nightly she sings on yond pomegranate tree. Believe me, love, it was the nightingale.\n\n"
  6. "Rom. It was the lark, the herald of the morn; No nightingale. Look, love, what envious streaks Do lace the severing clouds in yonder East. Night's candles are burnt out, and jocund day Stands tiptoe on the misty mountain tops. I must be gone and live, or stay and die.\n\n"
  7. "Jul. Yond light is not daylight; I know it, I. It is some meteor that the sun exhales To be to thee this night a torchbearer And light thee on the way to Mantua. Therefore stay yet; thou need'st not to be gone.\n\n"
  8. "Rom. Let me be ta'en, let me be put to death. I am content, so thou wilt have it so. I'll say yon grey is not the morning's eye, 'Tis but the pale reflex of Cynthia's brow; Nor that is not the lark whose notes do beat The vaulty heaven so high above our heads. I have more care to stay than will to go. Come, death, and welcome! Juliet wills it so. How is't, my soul? Let's talk; it is not day.\n\n"
  9. "Jul. It is, it is! Hie hence, be gone, away! It is the lark that sings so out of tune, Straining harsh discords and unpleasing sharps. Some say the lark makes sweet division; This doth not so, for she divideth us. Some say the lark and loathed toad chang'd eyes; O, now I would they had chang'd voices too, Since arm from arm that voice doth us affray, Hunting thee hence with hunt's-up to the day! O, now be gone! More light and light it grows.\n\n"
  10. "Rom. More light and light- more dark and dark our woes!\n\n"
  11. "More text here.")
  12.  
  13. print(re.findall(pattern, allLines, re.M))
Success #stdin #stdout 0.03s 9376KB
stdin
Standard input is empty
stdout
["Rom. It was the lark, the herald of the morn; No nightingale. Look, love, what envious streaks Do lace the severing clouds in yonder East. Night's candles are burnt out, and jocund day Stands tiptoe on the misty mountain tops. I must be gone and live, or stay and die.\n", "Rom. Let me be ta'en, let me be put to death. I am content, so thou wilt have it so. I'll say yon grey is not the morning's eye, 'Tis but the pale reflex of Cynthia's brow; Nor that is not the lark whose notes do beat The vaulty heaven so high above our heads. I have more care to stay than will to go. Come, death, and welcome! Juliet wills it so. How is't, my soul? Let's talk; it is not day.\n", 'Rom. More light and light- more dark and dark our woes!\n\nMore text here.']