我如何通过在 javascript 中使用正则表达式来通过点、逗号和换行符拆分字符串并删除空格?

How can i split a string by dot, comma and newline with removing whitespaces by using regex in javascript?

我有这样的字符串:

what, be inclined to, hi . hello 
where

我想这样拆分:

["what","be inclined to","hi","hello","where"]

目前我正在使用这个正则表达式,但它并不像我想要的那样工作:

input_words.val().replace(/^\s*|\s*$/g, '').split(/\n|\s*,|\./);

split 函数本身就足够了。下面的正则表达式将根据一个或多个逗号或点或换行符以及前面或后面的零个或多个空格来拆分您的输入。

var s = "what, be inclined to, hi . hello\nwhere";
alert(s.split(/\s*[,\n.]+\s*/))

var test ="what, be inclined to, hi . hello\nwhere";
var elements = test.split(/[,\n.\s+]+/) || [];