I would like this url:
http://bulk-click.startappsdasdasice.com/tracking/adClick?d=scsdc%20cdcsc%20c
to become
bulk-click.startappsdasdasice.com/tracking
I need this kind of pattern for all urls. so the string with the question mark and onward need to be deleted
There are several ways for this one of them is
var url="http://bulk-click.startappsdasdasice.com/tracking/adClick?d=scsdc%20cdcsc%20c"; var suburl=url.substring(0,url.lastIndexOf("/")).replace(/(^\w+:|^)\/\//, ''); console.log(suburl);
You may want to consider using a regular expression
var myRe = new RegExp('([http|https]://)(.+)(\/.+\?)', 'g'); var myArray = myRe.exec('http://bulk-click.startappsdasdasice.com/tracking/adClick?d=scsdc%20cdcsc%20c'); console.log(myArray[2]);
You can use the URL
interface to achieve this and substring till the last pathname (/adClick)
let url = new URL('http://bulk-click.startappsdasdasice.com/tracking/adClick?d=scsdc%20cdcsc%20c'); console.log(url.host + url.pathname.substring(0, url.pathname.lastIndexOf('/')))
Good idea. But use lenght const, because it assigns meaning specifically to this URL, and not to all the meanings of the URL above
const myRe = new RegExp('([http|https]://)(.+)(/.+\?)', 'g'); const myArray = myRe.exec(' http://bulk-click.startappsdasdasice.com/tracking/adClick?d=scsdc%20cdcsc%20c '); console.log(myArray[2]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.