i need split string 1 or more substrings each of contains no more or less 2 dots. example, if string foo.boo.coo.too"
regex following array?: ["foo.boo.coo", "boo.coo.too"]
. hope there answer question - admire you, i've been programming several years , have not still used regular expressions enough solve particular problem myself. thank in advance. let me know identity can credit contributor of program creating.
regex problem not best solution similar problem discussed here: split-a-sting-every-3-characters-from-back-javascript
a javascript solution javascript function this
function splitter(text){ var parts = text.split("."); var times = parts.length - 2; var values = []; for(var index = 0; index<times;index++) { values.push(parts.slice(index,index+3).join(".")); } return values; } splitter("too.boo.coo.too") //=> result tested on chrome 25+ ["too.boo.coo", "boo.coo.too"]
i hope helps
if want use regex try lookhead stuff, http://www.regular-expressions.info/lookaround.html
Comments
Post a Comment