【发布时间】:2016-04-22 23:24:36
【问题描述】:
如何直接从下划线中捕捉字符串?
我不希望下划线成为结果的一部分。
结果应该是:this is a test
而不是_this is a test。
我想用正则表达式解决这个问题,因为我试图理解 不同的场景。
var re = /(?:_)(.*)/g;
var str = 'foo _this is a test';
var m;
m = re.exec(str)
document.write(m[0]);
【问题讨论】:
-
你的正则表达式很好。执行您的正则表达式后,只需获得第二组。
-
非常感谢。我只是经验不足。
标签: javascript regex match extract regex-group