javascript 获取链接文件地址中第一个斜线内的正则表达式

时间:2024-02-25 07:53:28 

window.location.pathname
比如:
/windows/location/page.html
我想得到“windows”,请问用正则表达式怎么写?

<script> var a="/windows/location/page.html"; var reg=/(^(http[s]?:\/\/[^\/]*\/)|(^\/))([^\/]+)\/.*$/ig; var t=a.replace(reg,"$4"); alert(a + "\n" + "\n" + t); var a=top.location + "/windows/location/page.html"; var t=a.replace(reg,"$4"); alert(a + "\n" + "\n" + t); alert(top.location + "\n" + "\n" + reg.test(top.location)); </script>


标签:javascript,文件地址,斜线
0
投稿

猜你喜欢

  • python输出第n个默尼森数的实现示例

    2022-08-12 21:07:25
  • FCKeditor新版本发布,并更名为CKeditor

    2009-09-08 13:09:00
  • 利用JavaScript做数独的完整实现过程

    2024-02-24 02:10:47
  • 如何搜索查找并解决Django相关的问题

    2022-02-12 09:58:51
  • pandas中merge()函数的用法解读

    2023-10-02 08:49:46
  • Centos7 安装mysql 8.0.13(rpm)的教程详解

    2024-01-19 04:52:14
  • 对python3 sort sorted 函数的应用详解

    2022-08-01 23:44:45
  • [翻译]标记语言和样式手册 chapter 6 短语元素

    2008-01-25 16:37:00
  • Python使用matplotlib和pandas实现的画图操作【经典示例】

    2023-03-24 16:07:16
  • Python2与Python3的区别实例分析

    2021-01-07 11:47:17
  • MYSQL数据库使用UTF-8中文编码乱码的解决办法

    2024-01-23 00:22:28
  • itchat-python搭建微信机器人(附示例)

    2022-05-04 00:00:54
  • Python反射和内置方法重写操作详解

    2023-07-06 12:00:02
  • 使用DW中遇到的常见问题详解

    2008-03-18 16:27:00
  • Django实现文件上传下载功能

    2023-06-13 20:09:46
  • Python全局变量用法实例分析

    2023-08-03 13:39:18
  • Python 2.7中文显示与处理方法

    2021-06-14 16:07:39
  • python工具dtreeviz决策树可视化和模型可解释性

    2023-01-12 03:46:55
  • 一篇文章带你了解清楚Mysql 锁

    2024-01-24 21:17:43
  • 此数据库没有有效所有者,因此无法安装数据库关系图支持对象

    2024-01-16 15:23:27
  • asp之家 网络编程 m.aspxhome.com