正则表达式,又称规则表达式。(英语:Regular Expression,在代码中常简写为regex、regexp或RE),计算机科学的一个概念。正则表通常被用来检索、替换那些符合某个模式(规则)的文本。
关于正则表达式的文本规则可以在这片文章中搜索查看这里写链接内容
本文主要介绍正则表达式在siwft中的使用方式
NSRegularExpression 类是苹果对正则表达式的封装
@available(iOS 4.0, *)
open class NSRegularExpression : NSObject, NSCopying, NSSecureCoding {
public init(pattern: String, options: NSRegularExpression.Options = []) throws
open var pattern: String { get }
open var options: NSRegularExpression.Options { get }
open var numberOfCaptureGroups: Int { get }
open class func escapedPattern(for string: String) -> String
}
extension NSRegularExpression {
/* The fundamental matching method on NSRegularExpression is a block iterator. There are several additional convenience methods, for returning all matches at once, the number of matches, the first match, or the range of the first match. Each match is specified by an instance of NSTextCheckingResult (of type NSTextCheckingTypeRegularExpression) in which the overall match range <