I got it from Stack Overflow and then modified it to allow urls without the protocol.