I'm trying to split a string based on either spaces or certain symbols (presently *_-<>
). I'll give some examples of input and output:
"Hello how are you" -> [ "Hello", " ", "how", " ", "are", " ", "you" ]
"Hello *how* are *you*" -> [ "Hello", " ", "*how*", " ", "are", " ", "*you*" ]
"Hello *how*are_you_" -> [ "Hello", " ", "*how*", "are", "_you_" ]
"*how*are _you_ \*doing*_today_ hm?" -> [ "*how*", "are", " ", "_you_", " ", "\*doing*", "_today_", " ", "hm?"
Splitting on space unfortunately turns cases like *how*_are_
into a single item in the array instead of multiple items.
I also tried using a Regex to split on, but unfortunately it doesn't maintain the symbols surrounding each word.
Sorry if this is a bit confusing. Is there a good way to handle this?