Single character domains do not work properly in the current version (5.0.2) because the regex does not support it
I encountered some problems with shortened amazon links (https://a.co). These do not work with looseUrlRegex. Below is some code to reproduce the issue (the regex are taken directly from the library code):
Code
final _looseUrlRegex = RegExp(r'^(.*?)((https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))',
caseSensitive: false,
dotAll: true,
);
final _urlRegex = RegExp(r'^(.*?)((?:https?:\/\/|www\.)[^\s/$.?#].[^\s]*)',
caseSensitive: false,
dotAll: true,
);
print('match loose without https: ${_looseUrlRegex.firstMatch("a.co")?.group(0)}');
print('match regular without https: ${_urlRegex.firstMatch("a.co")?.group(0)}');
print('match loose with https: ${_looseUrlRegex.firstMatch("https://a.co")?.group(0)}');
print('match regular with https: ${_urlRegex.firstMatch("https://a.co")?.group(0)}');
Output
match loose without https: null // this should have a match
match regular without https: null
match loose with https: null // this should have a match
match regular with https: https://a.co
Single character domains do not work properly in the current version (5.0.2) because the regex does not support it
I encountered some problems with shortened amazon links (https://a.co). These do not work with
looseUrlRegex
. Below is some code to reproduce the issue (the regex are taken directly from the library code):Code
Output