HTML:
<input type="text" name="field" id="field" value="Select this text http://www.domain.com" />
JavaScript/JQuery:
$(document).ready(function()
{
var value = $('#field').val();
//select text
});
How can I select all the text that appears before a url? Everything after the url (including the url itself) should not be selected.
BTW, the text may also contain numbers and special characters.
Solution:
I ended up using Rocket’s solution split(/\shttps?:\/\//) (see below).
If the url will always be of the hypertext protocol, then you can do the following:
This will capture both http and https protocols, and is the least computing-intensive approach as far as I can tell.