I'd like to split this string by ' ' only if it has ':':
"A:Hey B:Are C:You there"
C:You there should be not split. The result should be:
["A:Hey", "B:Are", "C:You there"]
How can I do this?
\s+(?=\S*:)
You can split by this.
See demo.
https://regex101.com/r/hF7zZ1/4
This basically use a lookahead to make sure that the space which is being split upon is followed by non space characters and : .So it will work as you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With