I'd have a string that is something along the lines of:
"This is a string. $This is a word that has to be split. There could be $more than one in a string."
And I want to split it into an array so it ends up like this:
["This is a string. ", "$This", " is a word that has to be split. There could be ", "$more", " than one in a string."]
So basically, I need to have them split on '$' until just before the next space. I would also like to keep the spaces in the other strings if possible. Is there a way to do this with split()
or would regex need to be used here?