Is there an equivalent of the PhP function preg_split for JavaScript?
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.
The preg_split() function breaks a string into an array using matches of a regular expression as separators.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With