views:

38

answers:

1

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 :)

+3  A: 

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

var tags = str.split(/\s*[ ,;]\s*/);
SLaks
hmmmmm, looks cool, I've tested it here http://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
CIRK
The `split` function returns an array.
SLaks
The `*` means to match zero or more of the previous item. `\s` means any (single) whitespace character.
SLaks
Hey thanks! You are an angel :D Let me try it in my app
CIRK