Parsing Scenes From A Screenplay

Viewed 61

Hi I'm trying to parse out scenes from a screenplay. I recently posted about dialogue and the regex pro @Wiktor Stribiżew helped me out. I was able to use this pattern to almost capture the scenes perfectly however Im looking for a little more help.

So you'll see I've captured two groups. group 1 for the EXT and INT which indicate a new scene and group 2 for the content of the scene. However, I'm looking to add BURNETT HOUSE - DAY to group 1. Basically adding context to the scene. This almost does it ([A-Z]+\b.) but Im not sure how to merge it and it's sloppy and catches some single capital letters.

7    INT. COLONY HOTEL - STAIRWELL - NIGHT                       7
     Lowrey and Burnett clip on their shields and unholster
     their guns. The posing is over. This is business.


A8   INT. COLONY HOTEL - SUITE 202 - NIGHT                       A8
     On the table are two briefcases. Each opened. One
     containing cocaine. The other, cash. A pistol next
     to each.
       

enter image description here

1 Answers

You can use

\b((?:INT|EXT)\..*\S)[^\S\n]+[a-zA-Z]*\d+\n(?s:(.+?)(?=\b(?:EXT|INT)\.|\Z))

See the regex demo.

Details:

  • \b - word boundary
  • ((?:INT|EXT)\..*\S) - Group 1: INT or EXT, then a ., then any zero or more chars other than line break chars as few as possible, and then a non-whitespace char
  • [^\S\n]+ - one or more whitespaces other than a newline char
  • [a-zA-Z]* - zero or more ASCII letters
  • \d+ - one or more digits
  • \n - a newline
  • (?s: - start of an innline modifier group where . matches any char:
    • (.+?) - Group 2: one or more chars as many as possible
    • (?=\b(?:EXT|INT)\.|\Z) - up to the leftmost EXT or INT followed with a dot, or till the end of string
  • ) - end of the group.
Related