登录  /  注册
JavaScript正则表达式用于URL检测和拆分
P粉043432210
P粉043432210 2023-09-21 18:00:47
[JavaScript讨论组]

我有以下URL:

https://comanage.example.edu/sp
https://wiki.cs.example.org/sp
https://intranet.math.example.edu/sp
https://myapp.example.com/sp

对于这些URL,我需要定义一个函数来检测它们是否为URL,并从中替换掉https://和sp路径。基本上,我只需要主机名。例如,如下所示:

https://comanage.example.edu/sp      ->comanage.example.edu
https://wiki.cs.example.org/sp       ->wiki.cs.example.org
https://intranet.math.example.edu/sp ->intranet.math.example.edu
https://myapp.example.com/sp         ->myapp.example.com

对于非URL,该函数应该检测并不进行替换。如下所示:

nonurl.example.com -> ***no replacement***

请问有人能为我提供上述问题的解决方案吗?我对正则表达式的使用知识不多。

P粉043432210
P粉043432210

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号