Extracting Regular Expression Matches in Swift
Hello everyone! I'm new to Swift and trying to extract data from a string using regular expressions. I have a string like: "Hello, my name is Ivan, I'm 25 years old, I live in Moscow". I want to extract the name, age, and city separately. In other languages (e.g., Python), I used `re.findall()`, but in Swift it's different.\n\nI tried using `NSRegularExpression`, but got confused. Here's my code:\n\n```swift\nlet text = "Hello, my name is Ivan, I'm 25 years old, I live in Moscow"\nlet pattern = "Ivan|25|Moscow"\nlet regex = try? NSRegularExpression(pattern: pattern)\nlet matches = regex?.matches(in: text, range: NSRange(location: 0, length: text.utf16.count))\nfor match in matches ?? [] {\n print((text as NSString).substring(with: match.range))\n}\n```\n\nThis works, but only if I hardcode the val