[英]Javascript Regex Split Words that ends with dot, exclamation, question mark, comma and on whitespace
I need to split a string on words that ends with a dot, exclamation/question mark, comma and space.我需要在以点、感叹号/问号、逗号和空格结尾的单词上拆分字符串。
For example:例如:
var s = "An example, string, That have weird? formatting!"
When on s.split()
will result in:在
s.split()
将导致:
["An", "example", ",", "string", ",", "That", "have", "weird", "?", "formatting", "?"]
You should probably use match() with grouping to get what you want and not use split.您可能应该使用 match() 和分组来获得您想要的东西,而不是使用拆分。 The basic idea is match a word or match the special characters.
基本思想是匹配一个单词或匹配特殊字符。
var str = "An example, string, That have weird? formatting!" var result = str.match(/(\\w+|[,?!])/g) console.log(result)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.