I am trying to find a substring in another string. I am using Regular expressions. The code is as below:
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.")
}
Why is my substring "Kingfisher:" not getting found.