Deep Dives
- Swift Regex Deep Dive | Intro to Regular Expressions | Big Nerd Ranch
- Swift Regex with practical examples | Medium
Playgrounds
Overview
Regular expressions are a concise way of describing a pattern, which can help you match or extract portions of a string. You can create a Regex
instance using regular expression syntax, either in a regex literal or a string.
You can use a Regex
to search for a pattern in a string or substring. Call contains(_:)
to check for the presence of a pattern, or firstMatch(of:)
or matches(of:)
to find matches.
When you find a match, the resulting Regex.Match
type includes an output
property that contains the matched substring along with any captures:
When you import the RegexBuilder
module, you can also create Regex
instances using a clear and flexible declarative syntax. Using this style, you can combine, capture, and transform regexes, RegexBuilder
types, and custom parsers.