javascript - Regular expression improvement -


i trying write regular expression capture data, struggling finish it.

from data:

code:name another-code:another name 

i need array:

['code:name', 'another-code:another name'] 

the problem codes can space.

i know how without using regular expressions, decided give them chance.

update: forgot mention number of elements can vary 1 infinity. data:

code:name -> ['code:name'] code:name code:name code:name -> ['code:name', 'code:name', 'code:name'] 

is suitable.

just split input according space followed 1 or more non-space characters , : symbol.

> "code:name another-code:another name".split(/\s(?=\s+?:)/) [ 'code:name', 'another-code:another name' ] 

or

> "code:name another-code:another name".split(/\s(?=[^\s:]+:)/) [ 'code:name', 'another-code:another name' ] 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -