Skip to content Skip to sidebar Skip to footer

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:

  1. split accepts the delimiter, and splits the string by the delimiter. You are looking for match.

  2. In the JavaScript syntax, # should be replaced with /. But you've combined the PHP and JS syntax, not valid.

  3. Lookbehinds are not supported by JS

  4. 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"