Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. iOS
  3. Regex

Regex

MITSwiftv1.1.0

A Swifty wrapper for NSRegularExpression that makes regular expressions more convenient and type-safe in Swift.

Visit WebsiteGitHubGitHub
335 stars16 forks0 contributors

What is Regex?

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.

Target Audience

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.

Value Proposition

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.

Overview

🔤 Swifty regular expressions

Use Cases

Best For

  • Validating and parsing text input in Swift applications
  • Performing complex string replacements with regular expressions
  • Extracting structured data from text using named capture groups
  • Implementing pattern matching logic in Swift switch statements
  • Working with multiline regex patterns with comments
  • Reducing boilerplate when using NSRegularExpression in Swift code

Not Ideal For

  • Projects targeting non-Apple platforms (e.g., Linux) where NSRegularExpression support may be incomplete or buggy
  • Developers needing advanced regex features beyond NSRegularExpression's syntax, like lookbehind assertions
  • Simple string manipulation tasks where Swift's native String methods or raw regex usage suffice without extra dependencies
  • Teams already using alternative Swift regex libraries (e.g., SwiftRegex or custom solutions) and prefer to avoid migration overhead

Pros & Cons

Pros

Type-Safe API

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.

Convenient Matching Methods

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.

Named Capture Groups

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.

Pattern Matching Integration

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.

Cons

Limited to NSRegularExpression

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.

Dependency Overhead

Adds an external package dependency that may be unnecessary for projects with minimal regex needs, where raw NSRegularExpression or Swift string methods could suffice.

Platform Lock-in

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.

Frequently Asked Questions

Quick Stats

Stars335
Forks16
Contributors0
Open Issues0
Last commit10 months ago
CreatedSince 2021

Tags

#ios#regex#nsregularexpression#swifty#regular-expression#pattern-matching#type-safe#swift-package#swift#string-manipulation#regular-expressions#macos

Built With

S
Swift

Links & Resources

Website

Included in

iOS51.7kSwift26.0k
Auto-fetched 18 hours ago

Related Projects

BonMotBonMot

Beautiful, easy attributed strings in Swift

Stars3,551
Forks194
Last commit2 years ago
SwiftRichStringSwiftRichString

👩‍🎨 Elegant Attributed String composition in Swift sauce

Stars3,147
Forks211
Last commit3 years ago
TwitterTextEditorTwitterTextEditor

A standalone, flexible API that provides a full-featured rich text editor for iOS applications.

Stars3,002
Forks171
Last commit3 years ago
TextAttributesTextAttributes

An easier way to compose attributed strings

Stars2,184
Forks119
Last commit6 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub