0

我试图在另一个字符串中找到一个子字符串。我正在使用正则表达式。代码如下:

let occurrence = "Kingfisher:"
let string = "Swiss: SW123123\nKingfisher: KF994455\nQuantus: QS12343\nJetAir: FF7865667\nThai:  TH123442\nDelta: D123FGR\nAmerican: AME9879567\nGoAir: GO345682\nCathey: CATH020234\n        "
if let range = string.range(of: "\\b\(occurrence)\\b", options: .regularExpression) {
    print(range)
} else {
    print(occurrence, "not found.")
}

为什么找不到我的子字符串“Kingfisher:”。

4

0 回答 0