First things first: Never actually do this. This is just a fun curiosity, for amusement value only.
Because of the way JavaScript’s search() method works, you can do:
var my_url = 'http://kai.mactane.org';
if (! my_url.search(/http:\/\/kai.mactane.org/)) {
alert("Your URL is http://kai.mactane.org");
} else {
alert("Nope, your URL isn't http://kai.mactane.org");
}
Try running this, and it will correctly claim that “Your URL is http://kai.mactane.org” — even [...]
Tag Archives: silly coding tricks
Silly Coding Tricks: “Inverted” String Match
Saturday, February 13th, 2010 – 4:20 pm