如何从字符串中提取与禁止单词数组中包含的单词相匹配的单词(并删除任何剩余的空格)?
给定一组禁用单词,如何从字符串中提取某些单词。
以下面的伍迪·艾伦名言为例:
Love is the answer,
but while you are waiting for the answer
sex raises some pretty good questions
这是要从字符串中提取的单词数组:
var forbidden = new Array("is", "the", "but", "you",
"are", "for", "the", "some", "pretty");
如何从字符串中提取任何单词,删除任何剩余的空格,以便最终得到以下结果:
Love answer, while waiting answer sex raises good questions
How would you extract certain words from a string, given an array of forbidden words.
Consider the following Woody Allen quote as an example:
Love is the answer,
but while you are waiting for the answer
sex raises some pretty good questions
And this is the array of words to extract from the string:
var forbidden = new Array("is", "the", "but", "you",
"are", "for", "the", "some", "pretty");
How would you extract any words from the string, any remove any left-over whitespace so that you end up with this result:
Love answer, while waiting answer sex raises good questions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下: http://jsbin.com/isero5/edit
Try it: http://jsbin.com/isero5/edit