gpt4 book ai didi

regex - 检查字符串是否有效,位智实时 map 链接

转载 作者:行者123 更新时间:2023-12-03 03:08:02 25 4
gpt4 key购买 nike

我正在尝试检查字符串是否是Waze Live Map中的有效深层链接。 Waze Live Map深层链接看起来像这样:https://www.waze.com/ul?place=ChIJj61dQgK6j4AR4GeTYWZsKWw&ll=37.42199990%2C-122.08405750&navigate=yes给定一个字符串,我想知道它是否是有效的位智实时 map 链接。最重要的是,我想知道它是否至少具有经度和纬度。
我尝试了以下方法:

String str = 'https://www.waze.com/ul?place=ChIJj61dQgK6j4AR4GeTYWZsKWw&ll=37.42199990%2C-122.08405750&navigate=yes'; 
var wazeUrlPattern = r"https:\/\/www.waze.com\/ul\?ll\=(.)*([1-9]+\.[1-9]+)%2C([1-9]+\.[1-9]+)(.)?";
bool valid = new RegExp(wazeUrlPattern, caseSensitive:false).hasMatch(str);
if(!valid) {
print("The url is not valid waze live map link!");
return;
}
// Do something with the longitude and latitude and maybe other parameters
这对我不起作用,我希望找出一些帮助。

最佳答案

使用

https://www\.waze\.com/ul\?.*?&ll=(-?\d+\.\d+)%2C(-?\d+\.\d+)
参见 proof
转义点以匹配文字点,您将拥有 ?ll,而URL中稍后有 ?place&ll=。另外,经度和纬度可能在前面带有可选的 -
EXPLANATION
NODE                     EXPLANATION
--------------------------------------------------------------------------------
https://www 'https://www'
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
waze 'waze'
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
com/ul 'com/ul'
--------------------------------------------------------------------------------
\? '?'
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
&ll= '&ll='
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
-? '-' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
%2C '%2C'
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
-? '-' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
) end of \2

关于regex - 检查字符串是否有效,位智实时 map 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63209425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com