0
我使用:正則表達式g是全局搜索
var test = "pizzazz"
if let match = test.range(of: "g/zz", options: .regularExpression) {
print(test.substring(with: match))
}
這 如何設置全局搜索摹?
我使用:正則表達式g是全局搜索
var test = "pizzazz"
if let match = test.range(of: "g/zz", options: .regularExpression) {
print(test.substring(with: match))
}
這 如何設置全局搜索摹?
我不知道什麼應該是你的榜樣的結果,但你可能尋找這些功能之一:
1)
func enumerateMatches(in string: String,
options: NSRegularExpression.MatchingOptions = [],
range: NSRange,
using block: (NSTextCheckingResult?, NSRegularExpression.MatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void)
https://developer.apple.com/reference/foundation/nsregularexpression/1409687-enumeratematches
2)
func matches(in string: String,
options: NSRegularExpression.MatchingOptions = [],
range: NSRange) -> [NSTextCheckingResult]
https://developer.apple.com/reference/foundation/nsregularexpression/1412446-matches
3)
func stringByReplacingMatches(in string: String,
options: NSRegularExpression.MatchingOptions = [],
range: NSRange,
withTemplate templ: String) -> String
4)
func replaceMatches(in string: NSMutableString,
options: NSRegularExpression.MatchingOptions = [],
range: NSRange,
withTemplate templ: String) -> Int
https://developer.apple.com/reference/foundation/nsregularexpression/1411139-replacematches
這是全球默認 – Alexander
但 「ZZ」 只給我 「ZZ」 應該有兩根 - 這是兩個範圍 –
因爲你只要求單場比賽 – Alexander