Regex Tester for Swift
Free online regex tester with Swift code examples
Working with regex tester in Swift? Our free online regex tester helps Swift developers format, validate, and process data instantly. Below you will find Swift code examples using Foundation / Regex (built-in) so you can achieve the same result programmatically in your own projects.
Try the Regex Tester Online
Use our free Regex Tester directly in your browser — no setup required.
Open Regex TesterSwift Code Example
import Foundation
let text = "Contact support@example.com"
let pattern = try NSRegularExpression(pattern: "[\\w.+-]+@[\\w-]+\\.[\\w.]+")
let range = NSRange(text.startIndex..., in: text)
let matches = pattern.matches(in: text, range: range)
for match in matches {
print(String(text[Range(match.range, in: text)!]))
}Quick Setup
Library: Foundation / Regex (built-in)
// Built-in framework — no installation neededSwift Tips & Best Practices
- Swift 5.7+ has native Regex literals: /pattern/
- NSRegularExpression works on all Apple platforms
- Use RegexBuilder for type-safe regex in Swift 5.7+