NSRegularExpression Notes — Hi, I’m Sam

Hi, I’m Sam

This is my blog. I also have a website thing.

NSRegularExpression Notes

Posted on

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.

Front Matter

Here's my specific case (Jekyll front-matter):




NSRegularExpression(pattern: "\\A(---\\s*\\n.*?\\n?)^(---\\s*$\\n?)", options: .DotMatchesLineSeparators | .AnchorsMatchLines, error: nil)!