Skip to content

Instantly share code, notes, and snippets.

@mark-ingenosity
Last active December 3, 2019 04:44
Show Gist options
  • Select an option

  • Save mark-ingenosity/5f3a081643a11e26aad34c084ace41e1 to your computer and use it in GitHub Desktop.

Select an option

Save mark-ingenosity/5f3a081643a11e26aad34c084ace41e1 to your computer and use it in GitHub Desktop.
[WRITING: Python: Extract Dialog from Story Text] Strips all text not enclosed in double quotes leaving only dialog text (ex. "Some dialog text..."). #dialog #book #story #scrubbing
#!/usr/bin/env python3
#
# text2dialog.py
# Python script to strip dialog from story text, discarding all other narrative text.
# Uses open-close double quotes as delimeters.
#
import re, sys
with open(sys.argv[1]) as f:
reg = re.compile(r'"[^"]*"|\([^)]*\)')
for line in f:
print(' '.join(reg.findall(line)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment