Adam Halasz
Adam Halasz

Reputation: 58301

Javascript REGEX : Tags

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

Upvotes: 0

Views: 126

Answers (1)

SLaks
SLaks

Reputation: 887405

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

var tags = str.split(/\s*[ ,;]\s*/);

Upvotes: 3

Related Questions