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
Post a Comment