URL regex passed by regex buddy but failed by Dart

前端 未结 1 970
情书的邮戳
情书的邮戳 2021-01-27 01:50

I have the following regex in JavaScript regex

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


        
相关标签:
1条回答
  • 2021-01-27 02:41

    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');
    

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

    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.

    0 讨论(0)
提交回复
热议问题