我正在尝试从 js 代码中提取地址。
我从原始 javascript 中提取了以下行。
(new GLatLng(45.512242,-73.554009),'2860 Main Street S',icon_near)
我做了这个正则表达式
"\(new\sGLatLng\( #Start of the match
(?<Lat>\-?\d{1,3}.\d+) #Latitude
,
(?<Long>\-?\d{1,3}.\d+)\) #Longitude
,'
(?<Address>.+) #The address
(?=',icon_near\)) #Positive LookAhead. The regex end just before ',icon_near)"
问题是我有多个地址在一起,正则表达式匹配直到找到最后一个 ,icon_near\)
才会停止。
我用这个正则表达式解决了我的问题:
,
'(?<Address>.+?)'
(?=,icon_near\))
最佳答案
试试这个:
\(new\sGLatLng\( #Start of the match
(?<Lat>\-?\d{1,3}.\d+) #Latitude
,
(?<Long>\-?\d{1,3}.\d+)\) #Longitude
,
'(?<Address>.+)' #The address
(?=,icon_near\)) #Positive LookAhead. The regex end just before ',icon_near)
单引号放错地方了。此外,我删除了一个不需要的单引号。
演示
关于c# - 正则表达式从js代码中提取地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21287876/