ruby - String split by certain condition -


i'd split string ' ' if has ':':

"a:hey b:are c:you there" 

c:you there should not split. result should be:

["a:hey", "b:are", "c:you there"] 

how can this?

\s+(?=\s*:) 

you can split this.

see demo.

https://regex101.com/r/hf7zz1/4

this use lookahead make sure space being split upon followed non space characters , : .so work want.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -