112
rated 0 times
[
116]
[
4]
/ answers: 1 / hits: 21942
/ 13 Years ago, fri, december 9, 2011, 12:00:00
Suppose I've a long string containing newlines and tabs as:
var x = This is a long string.nt This is another one on next line.;
So how can we split this string into tokens, using regular expression?
I don't want to use .split(' ')
because I want to learn Javascript's Regex.
A more complicated string could be this:
var y = This @is a #long $string. Alright, lets split this.;
Now I want to extract only the valid words out of this string, without special characters, and punctuation, i.e I want these:
var xwords = [This, is, a, long, string, This, is, another, one, on, next, line];
var ywords = [This, is, a, long, string, Alright, lets, split, this];
More From » regex