This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 8 years ago.
We have regex to validate URL. I need a regex that will validate against it. Kindly help me in this.
URL for proper validation
var regexp = /(ftp|http|https)://(\w+:{0,1}\w*#)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%#!-/]))?/
What's for validating against, i.e it should not be a URL.
Just negate the regex using negative lookahead,
^(?!^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+#)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+#)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%#.\w_]*)#?(?:[\w]*))?)$).*$
DEMO
Related
This question already has answers here:
Regex Until But Not Including
(3 answers)
Closed 3 years ago.
I'm currently struggling with finding a way to extract domain names in urls.
My strings
xyz.weam.com
we2.wal.com
abc.workwork.google.net
I would like it to look for (com|org|net) and take the string before the match including the match until it hits the first (.) going backwards.
I have tried different combinations of lookbehind and positive lookahead but I was never able to make it stop at the right dot (.).
Thanks for the answers guys and especially to Aaron, his answer worked perfectly.
His Regex did the trick.
\.([^.]+).(?:com|net|org)$
This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 3 years ago.
I'm not sure what the code below means. I know how to use match, but I'm not sure on what the brackets and "^" signs mean. Is there a website to where I can understand what all you can do with match?
var imagesURL;
imagesURL = html.match(/CapImg[^"']*/g);
match is usually used along with RegExp to search through a data for a particular value or pattern of values. ..
You should rather go and read about JavaScript RegExp (or Regular Expression).
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
This question already has answers here:
How to match all email addresses at a specific domain using regex?
(5 answers)
Closed 7 years ago.
I have written one regex to take only email domain as yahoo.com.
"^[a-zA-Z0-9]+#yahoo\.com$"
but when i enter amit.sahay#yahoo.com, it says invalid email id.
Please help.
Thanks.
You didn't added .(dot) within your character class over here so your updated regex would be
^[a-zA-Z0-9.]+#yahoo\.com$
//^^ added (.dot) over here
This question already has answers here:
Regular expression for first and last name
(28 answers)
Regex for names
(27 answers)
Closed 8 years ago.
I'm creating a web store and I need to validate inputs with JavaScripts so the user doesn't have to submit a form to be given the PHP errors (although I'm also validating the form with PHP).
What I came up with is the following regex:
/^[a-zA-Z]+$/
But the above regex would only allow alpha characters whereas I also want to allow characters such as ' and - since obviously names may also contain these two characters. My question is, how to make a regex to allow alpha characaters AND the two characters above.
Besides that I also have one more question which just came in my mind, characters such as ă will pass the above validation ?
By adding them to your character group like so
/^[a-zA-Z'-]+$/
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Validate email address in Javascript?
What is the best regular expression to check if a string is a valid URL?
I want to test that whether the string is url or not, right now I am stuck at this point.
I am using this regex to validate my URL
/(https|http):\/\/([_a-z\d\-]+(\.[_a-z\d\-]+)+)(([_a-z\d\-\\\.\/]+[_a-z\d\-\\\/])+)*/;
The problem with this regex is that it fails to validate this type of URL
http://www.abc/abc/
how to check that case.?