admin管理员组文章数量:1391937
i have this script:
val.split( /(?:,.| )+/ )
and i need to split any character different from letter, like new line, white space, "tab" or dot... etc
I know you cannot write all characters, so give me one good example.
i have this script:
val.split( /(?:,.| )+/ )
and i need to split any character different from letter, like new line, white space, "tab" or dot... etc
I know you cannot write all characters, so give me one good example.
Share Improve this question asked Mar 24, 2012 at 16:37 fire1fire1 821 silver badge10 bronze badges 1- regular-expressions.info/reference.html – Felix Kling Commented Mar 24, 2012 at 17:36
5 Answers
Reset to default 4I'd suggest, possibly:
val.split(/\W/);
References:
- RegExp, at the Mozilla Developer Network.
[\W_0-9]
should cover them all.
\W
: Everything which is not a letter, a number, or the underscore; then adding the _ and all digits from 0-9. This has the benefit of covering non ASCII letters such as é ü etc...
You can use []
to create a range of possible characters and prefix [^
to invert the range. So:
val.split(/[^a-z]+/i)
Try this:
var myString = "Hello, I'm a string that will lose all my non-letter characters (including 1, 2, and 3, and all mas... everything)"
myString.replace(/[^a-z\s]/gi, '').split(" ");
It'll split a string into an array, stripping out all non-letter characters as it goes.
I know you cannot write all characters, so give me one good example.
In character classes, you can enumerate characters with a -
; like so: [a-zA-Z]
and i need to split any character different from letter, like new line, white space, "tab" or dot... etc
You can negate a group of characters like this: [^a-zA-Z]
I have this script:
val.split( /(?:,.| )+/ )
Which can now be this script: val.split(/[^a-zA-Z]+/)
本文标签: JavaScript Jquery how to split any character different from textStack Overflow
版权声明:本文标题:JavaScript Jquery how to split any character different from text - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744753492a2623320.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论