c# - 正则表达式从js代码中提取地址

标签 c# .net regex

我正在尝试从 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)

单引号放错地方了。此外,我删除了一个不需要的单引号。

演示

http://regex101.com/r/sX8dB2

关于c# - 正则表达式从js代码中提取地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21287876/

相关文章:

c# - TFS C# API : Workspace. PendAdd 静默失败

javascript - 纯正则表达式解决方案,用于在无法依赖 document.createElement 的环境中从 HTML 字符串获取文本内容?

php - 字符串的特殊 preg_match

java - 正则表达式 : how to replace this string in java?

c# - Windows Azure 网站连接外部 SQL 服务器

c# - 删除数据库mdb表格中的一个表

c# - XPath 版本搜索

asp.net - 使用表单例份验证时获取 Windows 用户 ID

C# 获取泛型对象内部的对象

c# - UnauthorizedException 尝试使用 Windows TaskScheduler 包装器