URL正则表达式由正则表达式好友传递但DART失败 [英] URL regex passed by regex buddy but failed by Dart

查看:158
本文介绍了URL正则表达式由正则表达式好友传递但DART失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript regex中有以下正则表达式

I have the following regex in JavaScript regex

(https?|ftp)://([-A-Z0-9.]+)(/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#/%=~_|!:‌​,.;]*)?

它尝试验证和清空空格或URL。

It attempts to validate and empty space/s or a URL.

但是当我尝试在Dart中使用 RegExp

Yet when I attempt to use it in Dart RegExp

使用Perle flavor正则表达式,它不会验证。

that uses a Perle flavour regex, it does not validates.

任何帮助是值得赞赏的。

Any help is appreciated.

推荐答案

您的模式不会查找小写字符。您可以将 az 添加到相应的字符组,也可以使用 caseSenstivie:false >



Your pattern doesn't look for lowercase characters. Either you add a-z to the respective character groups or you use caseSenstivie: false as shown in the code.

var urlPattern = r"(https?|ftp)://([-A-Z0-9.]+)(/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#/%=~_|!:‌​,.;]*)?";
var result = new RegExp(urlPattern, caseSensitive: false).firstMatch('https://www.google.com');

如果结果是!= null,则找到匹配。

If the result is != null a match was found.

您的模式找不到 http:网址(只有 https ftp www.google.com
关于'空白'的声明可能适用于您原本的问题中的电子邮件正则表达式,而不是您在注释中添加的网址正则表达式。

Your pattern doesn't find http: URLs (only https or ftp) neither www.google.com. Your statement about 'empty space' might apply to your email regexp you had in your question originally but not to your URL regexp you added in your comment.

这篇关于URL正则表达式由正则表达式好友传递但DART失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆