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

javascript - How to process users in one specific order using map o each function? -

java - Two interface have same method name with different return type -

javascript - Linking from page A to a specific iframe on page B -