All Projects → cezheng → Pyswiftyregex

cezheng / Pyswiftyregex

Licence: mit
Easily deal with Regex in Swift in a Pythonic way

Programming Languages

python
139335 projects - #7 most used programming language
swift
15916 projects

Projects that are alternatives of or similar to Pyswiftyregex

Guitar
A Cross-Platform String and Regular Expression Library written in Swift.
Stars: ✭ 641 (+182.38%)
Mutual labels:  carthage, regex
Anyformatkit
Simple text formatting in Swift
Stars: ✭ 296 (+30.4%)
Mutual labels:  carthage, regex
Pluck
Pluck text in a fast and intuitive way 🐓
Stars: ✭ 202 (-11.01%)
Mutual labels:  regex
Fusuma
Instagram-like photo browser and a camera feature with a few line of code in Swift.
Stars: ✭ 2,434 (+972.25%)
Mutual labels:  carthage
Iso8601
ISO8601 date parser and writer
Stars: ✭ 213 (-6.17%)
Mutual labels:  carthage
Regex Automata
A low level regular expression library that uses deterministic finite automata.
Stars: ✭ 203 (-10.57%)
Mutual labels:  regex
Core Layout
Flexbox & CSS-style Layout in Swift.
Stars: ✭ 215 (-5.29%)
Mutual labels:  carthage
Regexpu
A source code transpiler that enables the use of ES2015 Unicode regular expressions in ES5.
Stars: ✭ 201 (-11.45%)
Mutual labels:  regex
Tutti
Tutti is a Swift library that lets you create tutorials, hints and onboarding experiences.
Stars: ✭ 224 (-1.32%)
Mutual labels:  carthage
Cache
Swift caching library
Stars: ✭ 210 (-7.49%)
Mutual labels:  carthage
Pincache
Fast, non-deadlocking parallel object cache for iOS, tvOS and OS X
Stars: ✭ 2,513 (+1007.05%)
Mutual labels:  carthage
Shsearchbar
The search bar that doesn't suck.
Stars: ✭ 206 (-9.25%)
Mutual labels:  carthage
Swiftdailyapi
A Swift API framework for ZhiHu's Daily News.
Stars: ✭ 204 (-10.13%)
Mutual labels:  carthage
Aksidemenu
Beautiful iOS side menu library with parallax effect. Written in Swift
Stars: ✭ 216 (-4.85%)
Mutual labels:  carthage
Retina
A regex-based programming language.
Stars: ✭ 202 (-11.01%)
Mutual labels:  regex
Tj
stdin line timestamps. single binary, no dependencies. osx & linux & windows. plays well with jq.
Stars: ✭ 218 (-3.96%)
Mutual labels:  regex
Inapppurchase
A Simple and Lightweight framework for In App Purchase
Stars: ✭ 202 (-11.01%)
Mutual labels:  carthage
Learn gnugrep ripgrep
Example based guide to mastering GNU grep and ripgrep
Stars: ✭ 204 (-10.13%)
Mutual labels:  regex
Theanimation
Type-safe CAAnimation wrapper. It makes preventing to set wrong type values.
Stars: ✭ 214 (-5.73%)
Mutual labels:  carthage
Admozaiccollectionviewlayout
ADMozaicCollectionViewLayout is yet another UICollectionViewLayout subclass that implements "brick", "mozaic" or Pinterest style layout.
Stars: ✭ 226 (-0.44%)
Mutual labels:  carthage

PySwiftyRegex

Cocoapods Compatible License Carthage Compatible Platform Twitter

Easily deal with Regex in Swift in a Pythonic way.

简体中文 日本語 한국어

This is Easy

import PySwiftyRegex

if let m = re.search("[Tt]his is (.*?)easy", "I think this is really easy!!!") {
	m.group()  // "this is really easy"
	m.group(1) // "really "
}

See More examples.

Requirements

  • iOS 7.0+ / Mac OS X 10.9+
  • Xcode 8.0+

< For Swift 2.3 please use version 0.3.0.

Installation

Embedded frameworks require a minimum deployment target of iOS 8 or OS X Mavericks.

To use PySwiftyRegex with a project targeting iOS 7, consider using CocoaSeeds or copy the PySwiftyRegex.swift file into your project.

CocoaPods(iOS 8+, OS X 10.9+)

You can use Cocoapods to install PySwiftyRegex by adding it to your to your Podfile:

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
	pod 'PySwiftyRegex', '~> 1.0.0'
end

Then, run the following command:

$ pod install

Carthage(iOS 8+, OS X 10.9+)

Adding the following line to your Cartfile or Cartfile.private:

github "cezheng/PySwiftyRegex" ~> 1.0.0

Run the following command:

$ carthage update

Then drag the PySwiftyRegex.framework built by Carthage into your target's General -> Embedded Binaries.

CocoaSeeds (for iOS 7)

CocoaSeeds allows you to use Swift libraries in iOS 7 projects.

Create Seedfile:

target :MyApp do
  github 'cezheng/PySwiftyRegex', '1.0.0', :files => 'PySwiftyRegex/PySwiftyRegex.swift'
end

Then run the following command:

$ seed install

Now you can see the PySwiftyRegex.swift file in your Xcode project. Build and enjoy!

Supported re methods

If you are familiar with Python's re module, you are ready to go. If not, you may like to check how Python's re is better than the cumbersome NSRegularExpression's APIs, by clicking at the items below.

re

re.RegexObject

re.MatchObject

More Usage Examples

Compile a RegexObject for future reuse

let regex = re.compile("this(.+)that")

Matching a pattern from beginning

if let m = regex.match("this one is different from that") {
	m.group()  //"this one is different from that"
	m.group(1) //" one is different from "
}

Searching a pattern (first match)

if let m = regex.search("I want this one, not that one") {
	m.group()  //"this one, not that one"
	m.group(1) //" one, not "
}

Find all occurrences of a pattern

regex.findall("this or that, this and that") // ["this or that", "this and that"]

Get match results for all occurrences of a pattern

for m in regex.finditer("this or that, this and that") {
	m.group()  // 1st time: "this or that", 2nd time: "this and that"
	m.group(1) // 1st time: " or ", 2nd time: " and "
}

Splitting a string with pattern

let regex = re.compile("[\\+\\-\\*/]")

// By default, will split at all occurrences of the pattern
regex.split("1+2-3*4/5")    // ["1", "2", "3", "4", "5"]

// Setting a maxsplit = 2
regex.split("1+2-3*4/5", 2) // ["1", "2", "3*4/5"]

Replacing a pattern

let regex = re.compile("[Yy]ou")

// Replacing all occurrences (2 times in this example)
regex.sub("u", "You guys go grap your food")     // "u guys go grap ur food"
regex.subn("u", "You guys go grap your food")    // ("u guys go grap ur food", 2)

// Setting maximum replace count = 1 (1 times in this example)
regex.sub("u", "You guys go grap your food", 1)  // "u guys go grap your food"
regex.subn("u", "You guys go grap your food", 1) // ("u guys go grap your food", 1)

License

PySwiftyRegex is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].