从特定点捕获字符串

catch string from a specific point

如何从下划线开始捕捉字符串?
我不希望下划线成为结果的一部分。

结果应该是: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]);

因为您不只是取第 1 组的值。您取而代之的是所有 Regex 值。代码应该是:

document.write(m[1]); // m[1] for taking group 1