Regular Expressions

From NSRegularExpression Tutorial and Cheat Sheet

This playground demonstrates a lot of the key features of NSRegularExpressions. Read through it, take a look at the results, and feel free to play around with any of the examples! At any point you can use the Editor > Reset Playground menu item to reset any of your changes.

Playground Setup

The functions in this section simply support the rest of the playground. They're used to highlight, list, and replace matches in strings, as well as listing groups. For any of the examples below, you should be able to see the effect in the results pane of the playground. For highlighting examples, hover over the result and click the eye or the plus icon to see the highlighted text.

The first time you look through these examples, don't feel like you have to understand all of the code below - instead, just scroll down to view the Basic Examples and Cheat Sheet.