Regular Expression Literals
One of the easiest ways to use regular expressions is with regular expression literals. With regular expression literals, we can create instances directly in our code using the / delimiter:
let pattern = /\b\w+\b/
text = "Hello from regex literal"
let matches = text.matches(of: pattern)
for match in matches {
    print("-- \(text[match.range])")
}
Here we begin by creating a regular expression literal. The pattern /\b\w+\b/ will match each word in a string. We use the matches() method to return an array of matches within the string, and then the for-in loop is used to loop through each match and output it to the console.
What makes regular expression literals even more powerful is that we can use them in String methods like range(of:), replacing(_, with:), wholeMatch(of:) and trimmingPrefix().
We can also use the Regex type that is part of the Swift standard library.