Regex by sindresorhus alternatives and similar libraries
Based on the "Text" category.
Alternatively, view Regex alternatives based on common mentions on social networks and blogs.
-
PhoneNumberKit
A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber. -
SwiftRichString
👩🎨 Elegant Attributed String composition in Swift sauce -
TwitterTextEditor
A standalone, flexible API that provides a full-featured rich text editor for iOS applications. -
RichEditorView
RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing. -
TextAttributes
An easier way to compose attributed strings -
SwiftString
A comprehensive, lightweight string extension for Swift -
edhita
Fully open source text editor for iOS written in SwiftUI. -
SwiftyAttributes
A Swifty API for attributed strings -
Atributika
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement. -
Notepad
[iOS] A fully themeable markdown editor with live syntax highlighting. -
MarkdownKit
A simple and customizable Markdown Parser for Swift -
Mustard
🌭 Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it. -
SwiftVerbalExpressions
Swift Port of VerbalExpressions -
PrediKit
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift. -
AttributedTextView
Easiest way to create an attributed UITextView (with support for multiple links and from html) -
Apodimark
Fast, flexible markdown parser written in Swift -
Regex by crossroadlabs
Regular expressions for swift -
PySwiftyRegex
Easily deal with Regex in Swift in a Pythonic way -
OysterKit
OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR -
Sprinter
A library for formatting strings on iOS and macOS -
Tagging
A TextView that provides easy to use tagging feature for Mention or Hashtag -
PredicateFlow
Write amazing, strong-typed and easy-to-read NSPredicate. -
Regex by brynbellomy
Regex class for Swift. Wraps NSRegularExpression. -
SmarkDown
A Pure Swift implementation of the markdown mark-up language -
OEMentions
An easy way to add mentions to uitextview like Facebook and Instagram -
Veneer
A simple library for building attributed strings, for a more civilized age.
Appwrite - The open-source backend cloud platform
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Regex by sindresorhus or a related project?
README
Regex
Swifty regular expressions
This is a wrapper for NSRegularExpression
that makes it more convenient and type-safe to use regular expressions in Swift.
Install
Add the following to Package.swift
:
.package(url: "https://github.com/sindresorhus/Regex", from: "0.1.0")
Usage
First, import the package:
import Regex
Examples
Check if it matches:
Regex(#"\d+"#).isMatched(by: "123")
//=> true
Get first match:
Regex(#"\d+"#).firstMatch(in: "123-456")?.value
//=> "123"
Get all matches:
Regex(#"\d+"#).allMatches(in: "123-456").map(\.value)
//=> ["123", "456"]
Replacing first match:
"123🦄456".replacingFirstMatch(of: #"\d+"#, with: "")
//=> "🦄456"
Replacing all matches:
"123🦄456".replacingAllMatches(of: #"\d+"#, with: "")
//=> "🦄"
Named capture groups:
let regex = Regex(#"\d+(?<word>[a-z]+)\d+"#)
regex.firstMatch(in: "123unicorn456")?.group(named: "word")?.value
//=> "unicorn"
switch "foo123" {
case Regex(#"^foo\d+$"#):
print("Match!")
default:
break
}
switch Regex(#"^foo\d+$"#) {
case "foo123":
print("Match!")
default:
break
}
Multiline and comments:
let regex = Regex(
#"""
^
[a-z]+ # Match the word
\d+ # Match the number
$
"""#,
options: .allowCommentsAndWhitespace
)
regex.isMatched(by: "foo123")
//=> true
API
FAQ
Why are pattern strings wrapped in #
?
Those are raw strings and they make it possible to, for example, use \d
without having to escape the backslash.
Related
- Defaults - Swifty and modern UserDefaults
- KeyboardShortcuts - Add user-customizable global keyboard shortcuts to your macOS app
- LaunchAtLogin - Add “Launch at Login” functionality to your macOS app
- More…