Javascript Split On Non-alphanumeric An Keep Delemiters At Start
I'm currently recoding some of my PHP code into javascript code for my node.js server. My PHP-Reqex looks like this: $timevalue = 'W5D4H7M34S12'; $aSplitted = preg_split('#(?<=\
Solution 1:
split
accepts the delimiter, and splits the string by the delimiter. You are looking formatch
.In the JavaScript syntax,
#
should be replaced with/
. But you've combined the PHP and JS syntax, not valid.Lookbehinds are not supported by JS
Just simplify it.
To get the matches, you should use
var timevalue = "W5D4H7M34S12";
var aSplitted = timevalue.match(/[a-z]\d+/ig);
document.write(JSON.stringify(aSplitted))
Post a Comment for "Javascript Split On Non-alphanumeric An Keep Delemiters At Start"