Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript equivalent of PhP preg_split

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

like image 291
Randomblue Avatar asked Jul 26 '11 01:07

Randomblue


People also ask

What is Preg_split function in PHP?

The preg_split() function is an inbuilt function in PHP which is used to convert the given string into an array. The function splits the string into smaller strings or sub-strings of length which is specified by the user. If the limit is specified then small string or sub-strings up to limit return through an array.

What is preg split?

The preg_split() function breaks a string into an array using matches of a regular expression as separators.


1 Answers

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.

like image 62
Mark Elliot Avatar answered Sep 20 '22 14:09

Mark Elliot