NSRegularExpression Tutorial and Cheat Sheet

A NSRegularExpression tutorial that shows you how to search, replace, and validate data in your app. Includes a handy NSRegularExpression cheat sheet PDF! By Soheil Azarpour.

Leave a rating/review
Save for later
Share
You are currently viewing page 5 of 5 of this article. Click here to view the first page.

Where To Go From Here?

Here is the final example project that you developed in the above tutorial.

Congratulations! You now have some practical experience with using regular expressions.

Regular expressions are powerful and fun to work with — they’re a lot like solving a math problem. The flexibility of regular expressions gives you many ways to create a pattern to fit your needs, such as filtering input strings for white spaces, stripping out HTML or XML tags before parsing, or finding particular XML or HTML tags — and much more!

There are a lot of real-world examples of strings that can be validated with regular expressions.
As a final exercise, try to untangle the following regular expression that validates an email address:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

It looks like a jumble of characters at first glance, but with your new-found knowledge (and the helpful links below) you’re one step closer to understanding it and becoming a master of regular expressions!

Here is a short list of some useful resources about regular expressions:

I hope you enjoyed this NSRegularExpression tutorial and cheat sheet, and if you have any comments or questions, please join the forum discussion below!

Contributors

Over 300 content creators. Join our team.