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]+/)