Javascript 如何在匹配之前提取所有单词?
是否有任何正则表达式将Javascript 如何在匹配之前提取所有单词?,javascript,regex,Javascript,Regex,是否有任何正则表达式将标题和地址从文本中分离到下面的输出 这就是我目前的情况: .+?(?=\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
标题
和地址
从文本中分离到下面的输出
这就是我目前的情况:
.+?(?=\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
文本:
.+?(?=\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
输出:
.+?(?=\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
你可以用
(.+?)\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 ]*))?
看
详细信息
-第1组:除换行符以外的任何1个或多个字符,尽可能少(.+?)
-0+空格\s*
-第2组:1+位,除换行符以外的任何0+字符,尽可能多,(\d+.*Singapore\d{6})
,然后是6位数字Singapore
-单词边界\b
-一个可选的(?:\r?\n(\+65\s*\d{4}\s*\d{4}))?
-CRLF或LF行结束\r?\n
-第3组:(\+65\s*\d{4}\s*\d{4})
,0+空格,4位数字,0+空格,4位数字。+65
将匹配0个或更多数字或空格[\d]*
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
可能是
/(.+?)\s*(\d++.*Singapore\d{6})\b/
?看见电话号码不应该出现在比赛中,对吗?如果可能的话我也想比赛谢谢(:Like?or?regex101.com/r/i0G0wH/2我认为这应该适合我的需要。但是,regex似乎也匹配完整的地址和电话?我希望它分开。谢谢你的帮助!很好的解释。我将对此竖起大拇指!!@Wiktor StribizewStribizew我已经给了你一票。再次感谢你的帮助。干杯!