使用正则表达式从url中删除主机名和端口 [英] remove hostname and port from url using regular expression

查看:1206
本文介绍了使用正则表达式从url中删除主机名和端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除

I am trying to remove

http://localhost:7001/

部分来自

part from

http://localhost:7001/www.facebook.com

得到输出为

to get the output as

www.facebook.com

什么是正则表达式,我可以用它来实现这个确切的模式?

what is the regular expression that i can use to achieve this exact pattern?

推荐答案

p>

To javascript you can use this code:

var URL = "http://localhost:7001/www.facebook.com";
var newURL = URL.replace (/^[a-z]{4,5}\:\/{2}[a-z]{1,}\:[0-9]{1,4}.(.*)/, '$1'); // http or https
alert (newURL);

看看这段代码在行动这里

问候,
Victor

Regards, Victor

这篇关于使用正则表达式从url中删除主机名和端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆