python - 返回对话行的正则表达式
问题描述
-我是初学者 python 编码器,所以请多多包涵!
- 一行完整的对话框被定义为从它自己的行开始并以双引号(即“)开始和结束的文本。
到目前为止我所拥有的是,
def q_4():
pattern = r'^\"\w*\"'
return re.compile(pattern, re.M|re.IGNORECASE)
但由于某种原因,它只返回一个实例,两个双引号之间有一个单词。我怎样才能掌握完整的线条?
解决方案
尝试搜索模式\"[^"]+\"
:
inp = """Here is a quote: "the quick brown fox jumps over
the lazy dog" and here is another "blah
blah blah" the end"""
dialogs = re.findall(r'\"([^"]+)\"', inp)
print(dialogs)
这打印:
['the quick brown fox jumps over\nthe lazy dog', 'blah\nblah blah']
推荐阅读
- python - 轮播滑动方向的 Kivy RecycleView 不起作用
- reactjs - 有没有办法在 react-admin 的 ReferenceArrayInput -> SelectArrayInput 组件中显示预先选择的项目?
- node.js - 重新加载时反应Nodejs页面空白
- ios - 当环境对象更新导致同一视图重新加载时,如何导航到另一个 SwiftUI 视图
- tkinter - 显示图像 tkinter 的问题
- typescript - 如何在泛型函数上使用正确的类型函数?
- pdfbox - Text displayed in blue although PDAnnotation removed
- r - Stack(),模型的 blending_predictions,导致警告:需要相关性计算,但估计值是恒定的,标准差为 0
- android - 如何在android中的所有活动之上显示自定义警报?
- java - 使用 Java stream() API 过滤掉没有 List 的单个元素