Reputation: 135
Some users using URLs (Domains) in there usernames. They are sometimes much different, so i want to filter them out in there name
I can str.replace
urls, if i know the urls, but there much different so i think regex is, how it works, but i try so much, but doesnt get any results...
I hope someone can help me.
I found that Regex for PHP but i need something for NodeJS / Javascript.
$regex = '/^(.*?)';
$regex .= "((https?|ftp)\:\/\/)?"; // SCHEME
$regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; // User and Pass
$regex .= "([a-z0-9-.]*)\.([a-z]{2,3})"; // Host or IP
$regex .= "(\:[0-9]{2,5})?"; // Port
$regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; // Path
$regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; // GET Query
$regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; // Anchor
$regex .= '(.*?)$/i';
A username looks like
USERNAME Google.com
but can also
USERNAME www.GOOGLE.com
or
USERNAME GOOGLE.GG
Upvotes: 0
Views: 633
Reputation: 3206
You can use this regex to check for URL. It's basic. You can extend it if you need.
((http|ftp|https):\/\/)?([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?
https://regex101.com/r/fMAMkA/1
Upvotes: 1