I spent awhile today trying to convert a regular expression from Ruby to NSRegularExpression. It was being dumb and took me awhile to figure it out.
The main this is NSRegularExpression's options. By default Ruby, has
AnchorsMatchLines on and NSRegularExpression doesn't. I simply turned that on and had good luck.
Here's my specific case (Jekyll front-matter):
NSRegularExpression(pattern: "\\A(---\\s*\\n.*?\\n?)^(---\\s*$\\n?)", options: .DotMatchesLineSeparators | .AnchorsMatchLines, error: nil)!