Although there's no doubt that regular expressions are incredibly useful, they also easily get out of hand when trying to match complex strings. Furthermore, anything past twelve or so characters gets hard to read and understand, which is a common source of bugs.
To work around this problem, I suggest you use an online site such as Regex101.com, which helps you check your regular expressions are correct by visually highlighting strings that match. It's fully compatible with all the options shown here, including string replacement, and can even break down a regex and describe it in plain English.
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!