I have the following function
static func replaceAtSignNotation(_ text : String) -> String {
var source = text
let wholePattern = "@\\[[a-z0-9-\\-]+\\]\\((\\w+)\\)"
let typePattern = "(?<=]\\()[^)]+(?=\\))"
if let wholeRange = source.range(of: wholePattern, options: .regularExpression) {
if let typeRange = source.range(of: typePattern, options: .regularExpression) {
let username = source[typeRange]
source.replaceSubrange(wholeRange, with: "@\(username)")
}
} else {
return text
}
return replaceAtSignNotation(source)
}
which is doing an excellent job finding patterns such as:
@[a12-3asd-32](john)
@[b12-32d1-23](martha)
And allowing me to catch the username, but some username do contain a '-' such as:
@[c12-12d1-13](john-user-1)
But my current regex is not capturing those cases. Any idea how I can adapt my regex to captuve those cases as well?