I concur that .split(by: RegexComponent) is the way to go as it accepts RegexComponent rather than .split(separator: Character) which just accepts a single character.
Here is an example of a case statement using Regexs.
// does a string start with a word of one or more letters?
var possibleWords = ["word", " text", "1stop", "-spaced", "987-", "987again"]
for word in possibleWords {
switch true {
case word.starts(with: /\d{3}-/) :
print("'\(word)' starts with 3-digits and a hyphen.")
case word.starts(with: /\d+/) :
print("'\(word)' starts with digit(s).")
case word.starts(with: /\w+/) :
print("'\(word)' starts with a word.")
case word.starts(with: /\s+/) :
print("'\(word)' starts with a whitespace.")
default:
print("'\(word)' had no Matches")
}
}
The output from this is
'word' starts with a word.
' text' starts with a whitespace.
'1stop' starts with digit(s).
'-spaced' had no Matches
'987-' starts with 3-digits and a hyphen.
'987again' starts with digit(s).
Hope this helps
Chris