javascript - 正则表达式匹配两个不同字符之间的所有内容

标签 javascript html regex string-matching

我想匹配(但不包括)这两个字符之间的字符串:?&

示例字符串:

localhost/path/doc.html?970441179&token=specialtoken&actionurl=/portletaction/01654/0112

所以从上面我想匹配字符串970441179

最佳答案

var str = "?samplestring&";
var patt = /[?]([^&]*)[&]/g;
var res = patt.exec(str)[1];

“res”是您想要的结果。

关于javascript - 正则表达式匹配两个不同字符之间的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44290659/

相关文章:

javascript - 将 html 事件绑定(bind)到函数

html - html的AngularJS动态lang属性

python - 美元金额,千位以逗号分隔

jquery - 当我选择特定选项 jQuery 时如何删除类

php - 正则表达式在字符上拆分字符串,内部字符串除外

regex - 在 zsh 正则表达式中匹配 unicode 字符

javascript - 确定一个节点是否与另一个节点重叠

javascript - 我的 JavaScript 时钟小部件使 Firefox 崩溃

javascript - 在html文本框中,如何显示本身包含 ""符号的值?

javascript - 网络应用程序 : Combining View Layer Between PHP and Javascript-AJAX