What’s new in Swift 5.7 | Regex Type & Regex Builder Api
Regex are very cool. Regexes, also known as regular expressions, are a powerful tool for matching patterns in text. Swift supports several ways to create a regular expression, including from a string, as a literal, and using this DSL.
‘Regex’ type, is a new type in the Swift Standard Library. A language built-in Regex literal syntax, which makes this powerful and familiar concept. And finally, a result builder API called RegexBuilder. It is a domain-specific language, or DSL.
Get Started
Here I’ll discuss about above 3 ways to create regex:
- Regex from String
- Regex as literal
- Regex by Builder api
Lets start with an example — I have a string which contains some hashtags. Now I’ll create regex to find all the hashtags from the string.
let text = "My #name is #sanjeev and I am an #engineer with #10 years of #experience. Currently, working on #apple #technology."