作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
将正则表达式 word
的开头和结尾定义为捕获组中的边界的正确语法是什么,如下所示:
var $classes = $( 'body' ).attr('class'); // string 'foo bar sub-theme-home';
var regex = /sub-theme-(?=(\b))/;
var sub_theme = regex.exec($classes);
console.log(sub_theme[0]);
这是匹配 sub-theme-
,虽然如果我需要将它包含在我的捕获中并进行字符串替换以将其删除是没问题的,但我无法找出适合我的语法的正确语法(?-(\b))/
捕获组。看起来像积极的前瞻,sub-theme-
应该是省略的部分,home
应该被捕获...帮助?
最佳答案
为什么不直接捕获您要查找的字符串?
var $classes = $( 'body' ).attr('class'); // string 'foo bar sub-theme-home';
var regex = /sub-theme-(\w+)/;
var sub_theme = regex.exec($classes);
console.log(sub_theme[1]);
在 MDN 查看更多关于带括号的子字符串和 regex.exec(...)
的结果的信息.
关于Javascript 正则表达式积极前瞻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13150800/
谁能解释当应用程序通过 802.11 WiFi 网络发送 UDP 单播数据报时它是如何工作的?假设非阻塞 UDP 套接字。具体而言,假设 802.11n 或 802.11ac 以及相当新的 Linux
我是一名优秀的程序员,十分优秀!