目前我使用/[\W]+/g
可以获得所有非单词字符,这正是我想要的。
然而,当连字符不被空格包围时(也就是作为连接词使用时),我希望省略它们。
例如:
var test = [
'e-mail', // Nothing shouldn't be captured
'e-commerce is great.', // Spaces and full stop should be captured
'He - yes he - went', // Dashes and white space should be captured
'He&-you, me-him' // &-, and the whitespace should be captured while the dash in me-him should not
]
\s
替换了[[:space:]]
的这个refiddle,看起来符合要求。 - dougBTV\s
而不是[:space:]。 - Tro