On the SitePoint PHP blog they've posted a tutorial from author Nicola Pietroluongo that wants to help demystify regular expressions with a few more real-world examples. He doesn't teach the foundations of regular expressions here and instead opts for a more "cookbook" approach with lots of little examples.
A regular expression is a sequence of characters used for parsing and manipulating strings. They are often used to perform searches, replace substrings and validate string data. This article provides tips, tricks, resources and steps for going through intricate regular expressions.
He starts with some basic tips around creating good regular expressions for your application: knowing the scenario you're matching, planning the requirements and implementing the match itself. His example expressions include matching for:
- simple passwords matching a policy
- valid URL matching
- HTML tag patterns
- finding duplicated words
Each example comes with the regular expression itself and an explanation of how it's doing the matching, breaking it down into each piece of the regex puzzle and how it relates to the match overall.