下面是我的正则表达式代码,但到目前为止我无法获取所需的输出。
(?:^|\r?\n)(.*?)\s\n?r([A-Z]+)r?\n\s(.*?)(?:\r?\n|$)
输入:
INT. JOHN AND LORI'S APARTMENT - NIGHT
John and Lori burst in with the remains of Ted. They're
both drenched from the rain. Lori frantically searches
drawers for sewing materials. She finds a needle and
thread, and John puts Ted on the table. Lori starts to
sew him up as John watches intently.
LORI
John... I don't know if this is gonna--
JOHN
Just try. Please. Just try.
我的目标是以下列方式获得输出:
John... I don't know if this is gonna--
JOHN
Just try. Please. Just try.
答案 0 :(得分:0)
您可以尝试使用:
failed
'[^\w] ([A-Z]+\\n\\n.+\\n)'
- 确保在大写文本之前没有任何字母出现(例如LORI,JOHN)
'[^\w]
- 查找大写单词,后跟空白行
[A-Z]+\\n\\n
- 查找不止一次出现并以新行结束的任何符号
这将找到大写名称
使用python正则表达式,.+\\n
保存您的整个文本:
text
这将输出:
LORI
约翰......我不知道这是不是 -
JOHN
试试吧。请。试试吧。