Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ArthurXHK/AXRegex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

14 Commits

Repository files navigation

AXRegex

Let's use Regex in a easy way with Swift.

[![CI Status](http://img.shields.io/travis/Arthur XU/AXRegex.svg?style=flat)](https://travis-ci.org/Arthur XU/AXRegex) Version License Platform

Why

Just want to implement a easy way to use regex in Swift.

简简单单调用正则表达式 ( ̄^ ̄)ゞ

Usage

You can match regex like this:

你可以这样用:

let regex = Regex("^[a-zA-Z0-9_-]{6,18}$")
regex.match("userNameA")
regex.match("userNameB")

or this:

或者这样用:

regexMatch("userName", pattern: "^[a-zA-Z0-9_-]{6,18}$")

even this:

甚至这样用:

"userName".regex("^[a-zA-Z0-9_-]{6,18}$")

But my favorites is like this:

不过我还是最喜欢这样用:

"userName" =~ "^[a-zA-Z0-9_-]{6,18}$"

All of them will return a struct "RegexResult"

这些方法都会返回一个结构体"RegexResult"。

public struct RegexResult {
 public let text: String
 public var matches: [(content:String, range: NSRange, type: NSTextCheckingType)]
 public var hasMatch: Bool
 public var isCompleteMatch: Bool
}

It also prepares some common pattern: Email, Website, IP Address, etc. Welcome for adding more.

还准备了一些常用的正则, 如: 邮箱, 网址, IP地址, 等等(欢迎大家来补充)。

"http://www.google.com" =~ RegexPattern.WebSite

Demo

I created a demo app for AXRegex. Welcome to create issues when you meet any problems.

本人创建了一个范例应用。若遇到任何问题,欢迎提问。

Demo

Requirements

  • Swift 2.0

Installation with CocoaPods

AXRegex is available through CocoaPods. To install it, simply add the following line to your Podfile:

platform :ios, '8.0'
pod 'AXRegex', :git => 'https://github.com/ArthurXHK/AXRegex.git'

Author

Arthur XU, arthurk.dev@gmail.com

License

AXRegex is available under the Apache License 2.0. See the LICENSE file for more info.

About

Let's use Regex in a easy way with Swift 2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /