0

I want to convert words into tags.

So for example I have an input, if I type in in this

apple, windows, stackoverflow, google, microsoft

then I will get this:

apple windows stackoverflow google microsoft

Delimiters should be space, semicolon, or comma, just like in stackoverflow :)

1 Answer 1

3

You can use the split method to split a string into an array, like this:

var tags = str.split(/\s*[ ,;]\s*/);
Sign up to request clarification or add additional context in comments.

3 Comments

hmmmmm, looks cool, I've tested it here regex.larsolavtorvik.com but why are there commas after each word? is it because of the array? and what are the * sry I'm new in regex
The split function returns an array.
The * means to match zero or more of the previous item. \s means any (single) whitespace character.

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.