JavaScript equivalent of PhP preg_split

Randomblue picture Randomblue · Jul 26, 2011 · Viewed 13.5k times · Source

Is there an equivalent of the PhP function preg_split for JavaScript?

Answer

Mark Elliot picture Mark Elliot · Jul 26, 2011

Any string in javascript can be split using the string.split function, e.g.

"foo:bar".split(/:/)

where split takes as an argument either a regular expression or a literal string.