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 “Regex – Find everything except – Caret” →
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.
Continue reading “Remove non-UTF8 characters from string with PHP” →
First off, regular expressions are great.
They are a handy quick way to validate or parse data and you can use them in almost all languages. But of all things, I forget neat regex’s and in fairness they are a pita to recall as the syntax is plain nutty.
This is where it ends. I am going to reference all the neat regex’s in this blog as I come across them rather than rely on mother Google.
Continue reading “Regular Expressions” →