Verify a URI in JavaScript with a Regular Expression using Google Search examples
This time it did it again: I used JavaScript. My need was to verify a basic URI in JavaScript, so I wrote this function based on RFC 3986 [WayBack] which in Appendix B has a nice regular expression: ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
function isValidUri(uri){
var uriRegExPattern = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?";
var uriRegEx = new RegExp(uriRegExPattern);
return (uriRegEx.test(uri));
}
It would crash. But JavaScript is JavaScript, so even a site like JSFiddle wouldn’t show an error (later I found out that enabling the console on http://jsbin.com/wamavacuco/edit?html,console,output does show the error in the console complete with stack trace).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Recently I did my very first JavaScript in HTML development. Since it was a one page experiment, I didn’t want to put it in an official repository of it’s own…
From the perspective of learning assembly language to get a grasp of thinking at the lowest computer abstraction, it is an ideal tutorial: the 6502 is a very simple 8-bit processor with only 3 registers. These restrictions make programming fun.
Nice question (thanks aplm!), as for instance Gist does not render html:
Pastebin is a useful online tool to paste snippets of text. Pastie is a similar tool. Also, Ideone is similar except that it also runs the source code, as well as being a general pastebin.
The idea is that you solve a task and learn from that, or learn by seeing how others have solved tasks or draft tasks.
So in a sense it is similar to the Rosetta stone: it has different languages phrasing the same tasks.
There are already a whole bunch of languages on RosettaCode (of which a few are in the categories below), and you can even suggest or add your own languages.
When you want to solve tasks, be sure to look at the list unimplemented tasks by language that leads to automatic reports by language (for instance two of the languages I use most often: C# and Delphi).