This question already has answers here:
Javascript regex to find a base URL
(2 answers)
Closed 6 years ago.
a simple regext that can test
Either but atleast one of (http, https, or www).
I've seen examples that has compulsion of protocol, or allows directly like google.com.
but for users, they are used to typing www., not all would type the protocol.
But still it should be a valid one, and not a "abced.com"
https://regex101.com/#javascript
there use (option1|option2|option3)
If you just need to test if the url starts with http, https, www then you can simply use /^(https?|www)/.
If you need a full regex for the url then check out Mathias Bynens post on the matter https://mathiasbynens.be/demo/url-regex and pick the one most suited to your needs.
Related
This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 2 years ago.
I am attempting to create a regular expression for validating edu emails which may or may not have a sub domain. Some schools have emails like "example#hms.harvard.edu" while other schools have emails like "example#stanford.edu".
([0-9]|[a-z]|[A-Z])+#([0-9]|[a-z]|[A-Z])+([0-9]|[a-z]|[A-Z])\.edu$"
This is the current regular expression that I have but I am not well versed in these.
I am looking to create an expression that will validate emails with one domain and emails with a subdomain.
Any help would be appreciated. Thanks!
In most cases, /^[-\w.]+#[-\w.]+\.edu$/ should be enough.
The only problem with this solution would be, that it can also accept domains like hms..harvard.edu.
To prevent this, you could use this regex instead: /^[-\w.]+#([-\w]+\.)*[-\w]+\.edu$/
Edit: use \w instead of [0-9a-zA-Z_]
This should do the trick (modified from http://emailregex.com/ - referenced in How to validate an email address using a regular expression?):
/^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+edu))$/
This question already has answers here:
UTF-8 all the way through
(13 answers)
How to store other languages (unicode) in cookies and get it back again
(1 answer)
Closed 5 years ago.
I'm building a references generator and I need to keep track of the generated references. To achieve this, I'm currently using Javascript to store a cookie containing the raw data, then a PHP page embedded on the result page takes the cookie and logs it into an HTML page, however, some characters appears like this : �. I really don't know which way to go to solve this (base64 encoding, unicode encoded characters...)
Here's the link to the website : http://louisfelixberthiaume.000webhostapp.com/source_siteweb.php
[It's in french]
I can't give you the link to the HTML page for obvious confidentiality reasons, however I'll provide a screenshot :
Generated references screenshot
This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 9 years ago.
I there any JavaScript way (regex) or module to check if a string is a URL which the follows following schema http://en.wikipedia.org/wiki/URI_scheme.
NOTE -
I have seen other questions related to this in stackoverflow and none of them are satisfactory.
Most of them are the regex which matches the http/https/ftp URL but what about feed or mailto URL or URL with any other schema as specified in http://en.wikipedia.org/wiki/URI_scheme
The following regex does what you are requesting.
It validates a string if it holds a URL as specified in RFC 3986.
Both absolute and relative URLs are supported.
^([a-z][a-z0-9+\-.]*:(//([a-z0-9\-._~%!$&'()*+,;=]+#)?([a-z0-9\-._~%]+|\[[a-f0-9:.]+\]|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\])(:[0-9]+)?(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?|(/?[a-z0-9\-._~%!$&'()*+,;=:#]+(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?)?)| ([a-z0-9\-._~%!$&'()*+,;=#]+(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?|(/[a-z0-9\-._~%!$&'()*+,;=:#]+)+/?))(\?[a-z0-9\-._~%!$&'()*+,;=:#/?]*)?(\#[a-z0-9\-._~%!$&'()*+,;=:#/?]*)?$
I did not come up with this regex, it is created by JGSoft
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Ways to circumvent the same-origin policy
Please help..
Mainly I want to parse a HTML from a different URL using JavaScript so I can find there if a class exists and I can show the result on my page if it exists or not.
I don't know your enviroment, but it looks like a jsonp :)
http://en.wikipedia.org/wiki/JSONP
1) You avoid same origin policy because You use src attribute of script tag.
2) You can have everything sent right into your callback function.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I parse a URL into hostname and path in javascript?
I’m trying to parse the url of the page. For example the current page is location.href.
So the main page of my blog, if I use alert(location.href); it will return “http://diaryofthedead.co.cc/” in an alert box. If I use alert(location.href); on page two of my blog, it will return “http://diaryofthedead.co.cc/page/2” in an alert box. Is there any way to parse the URL to get the number at the end. Does anyone know how I could do that? Could I use wildcard or something, to do something like: location.href+”page/”+*; While * is equal to whatever follows “page/”, and then turn * into a variable?
You can use
var pagenum = location.pathname.match(/\/page\/(.*)/)[1];
It will extract anything past '/page/' in your URL;
Checkout this package jsuri
Or keep it simple http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
URI.js is a library for working with URLs. It can not only parse URLs, but also offers a simple fluent API (jQuery like) for modifying URLs.
Take a look at the documentation on the location object http://www.w3schools.com/jsref/obj_location.asp
You first want the "pathname" part, location.pathname