Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract url from string with Javascript

Tags:

javascript

this sounds like something you could just google, but been looking for hours.

basically have this string i am ajaxing from another site

'function onclick(event) { toFacebook("http://www.domain.com.au/deal/url-test?2049361208?226781981"); }'

it comes out like that because im extracting the onclick.

i just want to extract the url from the string.

any help would be greatly appreciated.

---- edit ----

OK IF I GO HERE..http://regexlib.com/RESilverlight.aspx regext online tester

and run this regex.

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?

on my string, it highlights the url perfectly.. i just can get it to run with JS?

like image 995
Alessandro Avatar asked Jul 08 '26 05:07

Alessandro


1 Answers

if it is always with the dash (i'm assuming you want everything before the dash), you can use the split method:

var arr = split(val);

your data will be in arr[0]

like image 196
Brandon Frohbieter Avatar answered Jul 10 '26 18:07

Brandon Frohbieter