1

I need to Split complete document made out of text to separate words,how can I do this so it gives me each word alone , I used .Split function and It worked for the white space character , other than that no , I need a regex that can split the words based on (. and , and | and : and ; and ,)

any help ?

4
  • Show your code and some examples. Commented Oct 27, 2014 at 13:42
  • yourStringValue.split(/[.,|:;,]/); Commented Oct 27, 2014 at 13:44
  • You could replace all of the those characters with white space, the perform the split. Commented Oct 27, 2014 at 13:46
  • ok try: yourStringValue.split(/[.,|:;, ]/g); Commented Oct 27, 2014 at 13:51

1 Answer 1

2

Try this:

var text = "This; is my text. With|all,characters: to split,";
var arr = text.split(/[.|:;\s]/);

The [.,|:;,\s] is a character class, which contains all characters on which you want to split. \s indicates any whitespace (spaces, tabs ...).

Sign up to request clarification or add additional context in comments.

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.