views:

54

answers:

2

in a JavaScript, i am using Regex to split(/\W+/) to words.

when i split this, it's returning wrong value

var s3 = "bardzo dziękuję";
s3 = s3.split(/\W+/);


[0]: "bardzo"
[1]: "dzi"
[2]: "kuj"

How to fix this problem? please advice

+1  A: 

In this case, why not just split with whitespace?

s3.split(/\s+/);

Matt
A: 

The regex isn't splitting because it is treating your accented characters as non-word characters.

Use the whitespace special character:-

s3 = s3.split(/\s+/);
Paul Alan Taylor
thanks, it worked!
kakopappa