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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -