When working with regular expressions, it can be difficult to understand why a particualar pattern is not working as you would expect.
The visual debug tool at debuggex.com makes it much easier to step through and actually visualize how a pattern is working or, as is often the case, not working.
Here is an overview of how it works.
I found this regex useful when parsing log files to find everything except the data I needed. I can select and delete everything I don’t need and I am left with the lines of data I can work with. Continue reading
This may be a pretty rare problem but I’ll post it regardless.
A while ago, I came across a post on such a subject. It was written a few years ago but it’s still as relevant and useful as ever.
Neat way of removing excess whitespace and tabbing from strings.
$string = "Tom\tThumb\t is sooooooo\t\t\tdumb";
$string = preg_replace( '/\s+/', ' ', $string );
//will echo "Tom Thumb is sooooooo dumb"
Simple one. If you need to add/remove escape slashes to/from a string, use the following code.
If you have come across the cursed ‘Invalid Character‘ error while using PHP’s XML or JSON parser then you may be interested in this.