ios - Regex function to find @ mentions does not work anymore -
xcode 8.3.3
i wrote regex method mentions of string.
func getmentions() -> [string] { let pattern = "\\b@[a-za-z0-9]+" { let regex = try nsregularexpression(pattern: pattern, options: nsregularexpression.options(rawvalue: 0)) let nsstr = self nsstring let = nsrange(location: 0, length: nsstr.length) var matches : [string] = [string]() regex.enumeratematches(in: self, options: nsregularexpression.matchingoptions(rawvalue: 0), range: all) { (result : nstextcheckingresult?, _, _) in if let r = result { let result = nsstr.substring(with: r.range) string matches.append(result) } } log.info(matches) return matches } catch { return [] } }
this used work fine. however, when run this, empty matches. did updated now?
i've tried this:
let pattern = "\\b@[a-za-z0-9]+\\b"
Comments
Post a Comment