I am getting strings like "hello @[dbe9234d-9e59-94b01-42342c9sd](user_name) how are you?". I would like to use a regex to extract the 'user_name' part of the regular expression. I am using the following regex, which is returning the whole expression (and I only need the user_name) part. Any ideas?
let source = "hello @[dbe9234d-9e59-94b01-42342c9sd](user_name) how are you?"
typePattern = "@\\[[a-z0-9-\\-]+\\]\\((\\w+)\\)"
if let typeRange = source.range(of: typePattern,
options: .regularExpression) {
print("First type: \(source[typeRange])")
// First type: @[dbe9234d-9e59-94b01-42342c9sd](user_name)
}
"(?<=@\\[[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{8}\\]\\()[^()]+"