Given a block of text like so:
"Hello world this is http://yahoo.com "
On keypress I’m looking at the text for links. I don’t want to look for links in text while the user is still typing, example:
"Hello world this is http://yahoo.co"
How can I get everything in the text var starting from the left, 0, all the way to the last white space, meaning I don’t get a url while the user is typing it?
Thanks
UPDATED
Typing Hello world this is http://yahoo.com should return Hello world this is http://yahoo.com
Typing Hello world this is http://yahoo.co should return Hello world this is
Two methods:
First, a regular expression:
Second,
lastIndexOf:This latter only works with spaces, however, as
lastIndexOfdoesn’t take a regular expression.