I sometimes find writing regular expressions of any complexity difficult. That’s true, though it would be more accurate if I’d said always.
It’s not because regular expressions themselves are difficult (though there is a lot to remember, or look up), but it can be so easy to make mistakes and so difficult to find those mistakes in that confusing mass of characters.
Eventually I give up and make a dedicated PHP file just to test the regular expression against various inputs. In fact, I have done the same with other functions to ensure that they do what I expect them to.
And you know what they say: If you’ve done something more than once, and will probably do it again, why not automate it? And if you can’t automate it, make a tool for it. There’s even the more appropriate: Make a web-tool for testing functions with arguments.
(I have no idea if those are real saying or not.)
I like to listen to people and what they say, and so that is exactly what I did: http://gigglingcorpse.com/dev/phpfunctions
Here it is in iframe, although it doesn’t really fit: