假设我有一个包含换行符和制表符的长字符串:
var x = "This is a long string.\n\t This is another one on next line.";
那么我们如何使用正则表达式将该字符串拆分为标记呢?
我不想用.split(' ')
因为我想学习Javascript的正则表达式。
更复杂的字符串可能是这样的:
var y = "This @is a #long $string. Alright, lets split this.";
现在我只想提取有效的words从这个字符串中,没有特殊字符和标点符号,即我想要这些:
var xwords = ["This", "is", "a", "long", "string", "This", "is", "another", "one", "on", "next", "line"];
var ywords = ["This", "is", "a", "long", "string", "Alright", "lets", "split", "this"];