今日分享-swift正则表达式的应用

本文探讨了正则表达式在Swift中的应用,通过NSRegularExpression类进行文本规则匹配。以一个故事为例,展示了如何将文本中的特定词汇如'和尚'、'“'、'”'高亮显示,提醒读者在编程过程中避免过度抱怨,享受解决问题的乐趣。
摘要由CSDN通过智能技术生成

正则表达式,又称规则表达式。(英语: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 <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值