【发布时间】:2020-07-16 08:16:35
【问题描述】:
我想抓取给定关键字后的所有文本
Slot ID = 10, Machine type = 2000, Comments, FileName, Image Orientation = DecToSource, Background = 0, Center_X = 0, Center_Y = 0, OI = -1, AT angle = 0, Location X = 15.878, Location Y = 21.26
Slot ID A, Machine type = 2000, Comments, FileName, Image Orientation = DecToSource, Background = 0, Center_X = 0, Center_Y = 0, OI = 0.9, AT angle = 0, Location X
这个例子。如果我给出“Slot ID”,我的期望是抓住
"10,机器类型 = 2000,评论,文件名,图像方向 = DecTo## 标题 ##Source,背景 = 0,Center_X = 0,Center_Y = 0,OI = -1, AT 角 = 0,位置 X = 15.878,位置 Y = 21.26"
"A, 机器类型 = 2000,评论,文件名,图像方向 = DecToSource,背景 = 0,Center_X = 0,Center_Y = 0,OI = -1,AT 角度 = 0,位置X = 15.878,位置 Y = 21.26"
我尝试了下面的表达式,但这总是无法抓住“Slot ID =”的情况。
(?<=((Slot ID )|(Slot ID = ))).
哪一点错了?
【问题讨论】:
-
用什么语言?你已经标记了 Python 和 C#。
-
[python]、[c#] 和 [nsregularexpression] 不能混合使用。请仅使用相关标签。
-
适用于几乎所有正则表达式风格的最安全选项是
^Slot ID (?:= )?(.+)$,其中预期匹配将在第一个捕获组中。演示:regex101.com/r/cCZGvl/1