Circle ofLife
Circle ofLife

Reputation: 13

Splitting string by comma or colon

I'm trying to split string by comma or colon.

a-bc-de:fghij,klmn:opqrs should return an array of a-bc-de,fghij,klmn,opqrs

I've tried split(":|,") abd ("[^a-z]+") but I don't get the desired result.

Upvotes: 0

Views: 81

Answers (1)

Seblor
Seblor

Reputation: 7136

You are splitting by a string. If you want to split using a regex, you have to use the right syntax :

split(/:|,/)

Documentation link : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

Upvotes: 4

Related Questions