Javascript 正则表达式错误

Javascript 正则表达式错误,javascript,regex,Javascript,Regex,下面是我正在使用的正则表达式的最新版本,它抛出了无效正则表达式错误 任何具有正则表达式格式的foo都将不胜感激 下面是我的代码: // This function gets all the text in browser function getText() { return document.body.innerText; } var allText = getText(); // stores into browser text into variable //regex set

下面是我正在使用的正则表达式的最新版本,它抛出了无效正则表达式错误

任何具有正则表达式格式的foo都将不胜感激

下面是我的代码:

// This function gets all the text in browser
function getText() {
    return document.body.innerText;
}
var allText = getText(); // stores into browser text into variable

//regex set to rid text of all punctuaction, symbols, numbers, and excess  spaces
var matcher = new RegExp ("/(?<!\w)[a-zA-Z]+(?!\w)/", "g");

//cleanses text in browser of punctuation, symbols, numbers, and excess spaces
var newWords = allText.match(matcher);

//using a single space as the dividing tool, creates a list of all words
var Words=newWords.split(" ");
而不是

//regex set to rid text of all punctuaction, symbols, numbers, and excess  spaces
var matcher = new RegExp ("/(?<!\w)[a-zA-Z]+(?!\w)/", "g");
//cleanses text in browser of punctuation, symbols, numbers, and excess spaces
var newWords = allText.match(matcher);
//using a single space as the dividing tool, creates a list of all words
var Words=newWords.split(" ");
这将获得所有仅由ASCII字母组成的单词,如Stringmatch,再加上基于a/g的正则表达式,将获取与正则表达式匹配的所有子字符串,该正则表达式在单词边界之间匹配1个或多个ASCII字母


JS不支持查找,即?或?使用正则表达式文字语法或使用正则表达式构造函数1时。您不需要分隔符斜杠2。反斜杠应该是双转义的。使用新的RegExp?regex没有做你认为它是…@Tushar刚刚复制并粘贴了你的建议,我仍然收到相同的错误js不支持像?这样的lookbehind,请尝试\b。这不是重复,只是有很多问题。
var Words = allText.match(/\b[a-zA-Z]+\b/g); // OR...
// var Words = allText.match(/\b[A-Z]+\b/ig);