Grep to reformat screenplay dialogue into novel form?

16 views
Skip to first unread message

david nerlich

unread,
May 10, 2020, 9:53:58 AM5/10/20
to BBEdit Talk

Hi,


I’m trying to reformat screenplay dialogue into literary dialogue via grep. Example:


BILL


I like pizza.


into 


“I like pizza” said Bill.


An alternate source to edit would be to use all the hidden characters from Final Draft, eg:


 <Text>BILL</Text>

    </Paragraph>

    <Paragraph Type="Dialogue">

      <Text>I like pizza.</Text>



Thanks a bunch if anyone can advise how to do this. I’m a noob but I guess I need a wildcard like .* but with a function that includes it in the replace but preserving the unique name and dialogue in each instance. Hope that makes sense. 


Dave

Fletcher Sandbeck

unread,
May 10, 2020, 12:45:46 PM5/10/20
to bbe...@googlegroups.com
The basic idea is to define your search pattern with parentheses around the parts you want to use in the replacement. We might find the character name in all caps, two returns, and then the dialogue. You might need to add more \r return characters to match your source.

Search: ([A-Z ]+)\r\r(.*)\r
Replace: "\2" said \1.

Using the input string:

BILL

I like pizza.

This produces the output string:

"I like pizza." said BILL.

For the alternate source this might take the following form picking out the contents of the two <Text> tags and then using the same replacement pattern. The \s* is shorthand for any white space so we don't worry about how many tabs and returns there are.

Search: <Paragraph.*?>\s*<Text>(.*?)</Text>\s*</Paragraph>\s*<Paragraph Type="Dialogue">\s*<Text>(.*?)</Text>\s*</Paragraph>
Replace: "\2" said \1.


You can convert the character names from uppercase to title case using as second pass with a pattern like this. The (?-i) for case sensitivity. It finds words composed entirely of uppercase characters and then the replacement pattern capitalizes the first character and makes the rest lowercase. Watch out for acronyms and other input that might get converted.

Search: (?-i)([A-Z])([A-Z]+)\b
Replace: \u\1\L\2


The Pattern Playground is useful for trying these out.

[fletcher]
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/910a3a89-87c5-4af5-b42a-e391d321bfb0%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages