1

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

3 Answers 3

1

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+/);
Sign up to request clarification or add additional context in comments.

Comments

1

In this case, why not just split with whitespace?

s3.split(/\s+/);

Comments

1

You could use CharFunk https://raw.github.com/joelarson4/CharFunk , which handles Unicode fully.

var s3 = "bardzo dziękuję";

function notLetterOrDigit(ch) {
    return !CharFunk.isLetterOrDigit(ch);
}

CharFunk.splitOnMatches(s3, notLetterOrDigit);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.