A Swifty wrapper for NSRegularExpression that makes regular expressions more convenient and type-safe in Swift.
Regex is a Swift package that provides a convenient and type-safe wrapper around Apple's NSRegularExpression API. It simplifies working with regular expressions in Swift by offering a more Swifty interface that reduces boilerplate code and improves type safety while maintaining full compatibility with standard regex syntax.
Swift developers working on iOS, macOS, or other Apple platforms who need to work with regular expressions in their applications and want a more modern, type-safe API.
Developers choose Regex because it provides a cleaner, more Swifty API for regular expressions compared to using NSRegularExpression directly, with features like type-safe matching, convenient string replacement methods, and support for Swift's pattern matching syntax.
🔤 Swifty regular expressions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Reduces boilerplate and improves code safety with Swifty interfaces, such as concise method calls like `Regex(#"\d+"#).isMatched(by: "123")` instead of manual NSRegularExpression instantiation.
Simplifies common operations with methods like `firstMatch(in:)` and `allMatches(in:)`, making regex usage more readable and less error-prone, as shown in the README examples.
Provides easy access to named groups via the `group(named:)` method, enhancing code clarity when extracting specific data from matches, demonstrated in the unicorn example.
Seamlessly works with Swift's switch statements for expressive control flow, allowing direct use of regex patterns in case clauses, as illustrated in the README.
Inherits all constraints of Apple's NSRegularExpression, such as lack of support for certain Perl-compatible regex features, which can be a blocker for advanced use cases.
Adds an external package dependency that may be unnecessary for projects with minimal regex needs, where raw NSRegularExpression or Swift string methods could suffice.
Tightly coupled to Apple's Foundation framework, making it less suitable for cross-platform Swift projects on Linux or Windows where NSRegularExpression might behave differently.