I've been getting to grips with regular expressions over the past few weeks... something I've avoided for a couple of years. I'm finding them incredibly useful.
I've been following the basic regex tutorial on here written by Chris Corbyn, but I think this is calling for something a little more advanced.
This one has got me completely stumped.
I'm looking to count the number of double quote marks " in a variable that are outside a <> pair.
It's for a basic intranet-based CMS for our work website and it's one of the simple steps I'm taking to make sure the users enter at least structurally valid HTML.
So far I'm a long way off:
Code: Select all
echo preg_match_all('/<[^>]*/', $var, $matches);I've been using The Regex Coach, which is a really helpful utility for testing but I've hit a bit of a dead end on this.
I thought of using preg_split on the above which would give me an array of all the text outside of the <> pairs, and then I loop through the array and count the " characters.
But I'm sure there's a better way using regex
Any ideas/suggestions?
Thanks, B