我需要正则表达式方面的帮助。我需要创建一个规则来保留引号之间的所有内容并排除引号。例如:
我要这个...
STRING_ID#0="Stringtext";
……变成了……
Stringtext
Thanks!
做到这一点的方法是使用捕获组。然而,不同的语言处理捕获组的方式略有不同。这是 JavaScript 中的一个示例:
var str = 'STRING_ID#0="Stringtext"';
var myRegexp = /"([^"]*)"/g;
var arr = [];
//Iterate through results of regex search
do {
var match = myRegexp.exec(str);
if (match != null)
{
//Each call to exec returns the next match as an array where index 1
//is the captured group if it exists and index 0 is the text matched
arr.push(match[1] ? match[1] : match[0]);
}
} while (match != null);
document.write(arr.toString());
输出是
Stringtext
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)