是否有任何正则表达式将title和address从文本分离到下面的输出?
,到目前为止,这就是我所拥有的:
.+?(?=\d+.*Singapore \d{6}\b)文本:
Marina Bay Sands Relocated! 2 Bayfront Avenue Galleria Level #B1-01 Singapore 018972
+65 6634 9969
nex 23 Serangoon Central #B1-10 Singapore 556083
+65 6634 7787
Northpoint City 1 Northpoint Drive South Wing #B1-107 Singapore 768019
+65 6481 3433输出:
Marina Bay Sands Relocated!
2 Bayfront Avenue Galleria Level #B1-01 Singapore 018972
nex
23 Serangoon Central #B1-10 Singapore 556083
Northpoint City 1 Northpoint Drive South Wing #B1-107 Singapore 768019
+65 6481 3433发布于 2020-03-12 12:01:03
你可以用
(.+?)\s*(\d+.*Singapore \d{6})\b(?:\r?\n(\+65\s*\d{4}\s*\d{4}))?或者只是
(.+?)\s*(\d+.*Singapore \d{6})\b(?:\r?\n(\+65[\d ]*))?见regex演示。
详细信息
(.+?) -第1组:除换行字符以外的任何1或更多字符,尽可能少\s* - 0+白空间(\d+.*Singapore \d{6}) -第2组: 1+数字,除行中断字符以外的任何0+字符,尽可能多的Singapore,然后是6位数字。\b -字边界(?:\r?\n(\+65\s*\d{4}\s*\d{4}))? -一个可选的序列\r?\n - CRLF或LF线结束(\+65\s*\d{4}\s*\d{4}) -第3组:+65,0+白空间,4位数字,0+空格,4位数字。[\d ]*将匹配0或更多位数或空格。
每场比赛有三组内容:
Marina Bay Sands Relocated!
2 Bayfront Avenue Galleria Level #B1-01 Singapore 018972
+65 6634 9969
nex
23 Serangoon Central #B1-10 Singapore 556083
+65 6634 7787
Northpoint City
1 Northpoint Drive South Wing #B1-107 Singapore 768019
+65 6481 3433https://stackoverflow.com/questions/60653238
复制相似问题