javascript - javascript 中的 location.search.match

标签 javascript regex

大家好,我是初学者 CTF 玩家,我和 javascript 有同样的湖,我面临以下问题

我不明白下面一行的意图是什么

location.search.match(/e=(.*)/)[1]))

这是完整的代码

        if(location.search) {
        var div = document.currentScript.parentNode.appendChild(document.createElement('div'));
        div.className = 'alert alert-danger';
        div.role = 'alert';
        div.appendChild(document.createTextNode(unescape(location.search.match(/e=(.*)/)[1])));
    }

你能帮我理解一下吗

最佳答案

location.search基本上给你当前 URL 的查询字符串部分和 match已用于使用正则表达式从查询字符串中提取 e 参数值。

举个例子,如果当前的 URL 是这样的

https://www.example.com/?e=someone@example.com 然后 location.search.match(/e=(.*)/)[1] 会给你 'someone@example.com'。

其余代码主要是创建一个 div 元素并将提取的文本设置为它的子元素,最后将该 div 添加为当前运行脚本标签的父节点的子元素。

关于javascript - javascript 中的 location.search.match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44601229/

相关文章:

javascript - Google map API 未显示在 MVC5 中

javascript - Jquery UI 日期选择器不起作用

java - 如何使用正则表达式收集日志的不同部分

javascript - 在不知道索引的情况下从数组中删除对象

javascript - 错误 "File is a commonJS module; it may be converted to an ES6 module. ts(80001)"

javascript - 如何将变量插入到这个 json 对象中?

python - 正则表达式从以 _ 和 _ 下划线后的 str 结尾的字符串中获取数字

使用正则表达式的 HTML 时间输入验证(不允许 00 :00 but want allow 24:00)

regex - 如何匹配 IPv4 地址

java - 如何让整个单词使用子字符串?