我正在尝试使用 Vision Framework 从实体信用卡中读取泛号。为此,我使用字符串扩展来过滤结果。
以下是美国电话号码的示例:
func extractPhoneNumber() -> (Range<String.Index>, String)? {
let pattern = #"""
(?x) # Verbose regex, allows comments
(?:\+1-?)? # Potential international prefix, may have -
[(]? # Potential opening (
\b(\w{3}) # Capture xxx
[)]? # Potential closing )
[\ -./]? # Potential separator
(\w{3}) # Capture xxx
[\ -./]? # Potential separator
(\w{4})\b # Capture xxxx
"""#
guard let range = self.range(of: pattern, options: .regularExpression, range: nil, locale: nil) else {
// No phone number found.
return nil
}
我需要以下形式的卡盘编号的不同模式,例如。 0000 0000 0000 0000
谢谢您的帮助!
最佳答案
对我有用的模式是:
let pattern = #"""
\d{4} \d{4} \d{4} \d{4}
"""#
谢谢脚本!
关于ios - 如何在 Swift 中使用常规表达式设置信用卡 PAN NUMBER 的模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58995572/