忽略单词列表

Ignore Word List

本文关键字:列表 单词      更新时间:2023-09-26

我有一个要忽略的单词列表。 但是,当我调用它时,它会替换它的每个实例,即使它在字符串中也是如此。

例如:"他"最终将"the"变成"t"。

当单词独自一人时,我怎么能让它删除它们?

代码如下:

var commonWords=/and|a|an|has|he|to|was|in|were|are|is|will|as|it|if|
with|at|its|it's|be|by|on|that|from|the|about|again|all|almost|also|although|
always|among|another|any|be|because|been|before|being|between|both|by|can|could|
did|do|does|doesn't|'|done|due|during|each|either|enough|from|had|has|have|having|
here|i|if|into|is|isn't|itself|just|may|might|most|mostly|must|nor|no|neither|nearly|
of|often|on|our|ours|his|hers|he's|he|she|she's|overall|perhaps|quite|rather|really|
regarding|seem|seems|seen|several|should|show|showewd|shown|shows|significant|
significantly|since|so|some|such|than|that|then|their|theirs|there's|therefore|these|
they|this|those|through|thus|to|upon|use|used|using|various|very|was|we|were|what|when|
which|while|with|within|without|would|however|or|for|the|but|etc|yet|/g;
commonWords.ignoreCase;
var w = w.replace(commonWords, '');

您不是要替换字符串中的任何实例,而是要替换整个单词。您需要使用'b锚点查找单词边界。

例如。。。

var commonWords = /'b(and|a|an|has|he|she)'b/g;