您好,我正在运行最近的WWDC的文本识别示例,并且其中有正则表达式方法发生,我不确定它是如何工作的。有人能帮我吗?我从没使用过regex
let pattern = #"""
(?x) # Verbose regex, allows comments
(?:\+1-?)? # Potential international prefix, may have -
\b(\w{1, 4}) # Potential XXXX (
[\ ./]? # Capture espace
\b(\w{1, 4}) # Potential XXXX )
[\ ./]? # Potential espace
(\w{1, 4}) # Capture xxxx
[\ ./]? # Potential space
(\w{1, 3})\b # Capture xxxx
"""#
但不起作用
我已经对此进行了测试
let auxString = "1234 1234 1234 123"
guard let range1 = auxString.range(of: pattern, options: .regularExpression, range: nil, locale: nil) else {
// No phone number found.
print("no number found")
return nil
}