I am trying to split string in javascript by whitespaces, but ignoring whitespaces enclosed in quotes. So I googled this regular expression :(/\w+|"[^"]+"/g)
but the problem is, that this isn't working with accented chars like á etc. So please how should I improve my regular expression to make it work?
问问题
123 次
3 回答
1
这匹配不包含引号的非空格,并匹配引号之间的文本:
/[^\s"]+|"[^"]+"/g
于 2012-09-23T14:47:43.793 回答
1
那是因为\w
只有匹配[A-Za-z0-9_]
。要匹配重音\x81-\xFF
字符,请添加包含 Latin-1 字符和等à
的ã
unicode块范围:
(/[\w\x81-\xFF]+|"[^"]+"/g)
还有这个站点,它对构建所需的 unicode 块范围非常有帮助。
于 2012-09-23T14:34:08.443 回答
0
如果要匹配所有非空白字符而不是仅匹配字母数字字符,请替换\w
为\S
.
于 2012-09-23T14:40:15.843 回答