 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Padraic Brady's Blog: PCRE Regex Word Matching "w" vs "a-zA-Z0-9_"
by Chris Cornutt December 28, 2009 @ 09:41:21
Padraic Brady has posted about an issue he noticed when working with regular expressions and the "word" character type to find something that's alpha-numeric (including an underscore):
You can find the "word" generic character type used in a lot of PHP code including the Zend Framework. The problem is that the assumption above is incorrect. Now, most of the time these act identically because PHP is compiled using its own packaged PCRE library. However, I've seen more than once systems where this is not the case. Usually in some non-English capacity where additional locale support was considered necessary or standard practice.
The problem comes when PHP is compiled against a custom PCRE library, making it more locale-aware. He gives instructions on how to get this to a testable state on your environment (using an updated PREC library) and get it working for characters in French, like the accented "a" or "e".
voice your opinion now!
pcre regularexpression locale french
Jordi Boggiano's Blog: Major glob() fail
by Chris Cornutt December 07, 2009 @ 13:50:54
Jordi Boggiano had the "pleasure" of discovering a small quirk with PHP's glob function in an application he was working on - watch out for directories that contain square braces, they won't return in the results!
Working on some personal project that lists a bunch of stuff on my hard drive, I found out that directories that contain square brackets (those []) don't return any results for the simple reason that glob reads [stuff] as a character class, just like in regular expressions. When you know it it makes perfect sense, but when you don't, the documentation is really not so helpful. Of course it mentions libc's glob() and unix shells, but not everyone knows what that implies at first glance.
He tried a few things to get around the bug (including escaping the brackets in the directories) but ended up writing a function (glob_quote) to handle the escaping of all of the meta-characters glob might need to escape to return all of the files and folders correctly.
voice your opinion now!
glob fail regularexpression match
PHPFreaks.com: PCRE Regex Spotlight K
by Chris Cornutt August 25, 2009 @ 10:28:44
On the PHPFreaks.com blog today there's a quick new post looking at one of the special backslash strings that doesn't get talked about very much - K - but is quite powerful.
One backslash sequence that doesn't get much attention is K. What this handy little assertion does is match the position of whatever string comes before it in the pattern, then it in essence resets the match. At that point it starts a new match with whatever comes after K from the current location in the subject string.
They include a series of PHP code examples showing how use can use it to work around some of the issues with lookbehind assertions. They also include a few benefits and drawbacks of using them over lookbehinds.
voice your opinion now!
regularexpression regex assertion backslashk
DevShed: Working with Regular Expressions with Filters in PHP 5
by Chris Cornutt August 13, 2009 @ 08:10:06
New on DevShed today there's the fifth part of their series looking at validation and filtering in PHP5 applications.
Among the enhancements that were introduced originally in PHP 5, there's one powerful extension that has been all but ignored by many programmers until now, quite possibly because they weren't aware of its existence. [...] In this fifth part of the series, I'm going to discuss the usage of the [filter] extension for checking if the value that has been assigned to a given variable follows a specified regular expression pattern.
They include examples of using the FILTER_VALIDATE_REGEX option for filter_var to check the input against a given format. You'll have to find an introduction to regular expressions someplace else, though - they just assume you know how to work with them.
voice your opinion now!
tutorial filter extension regularexpression
PHPBuilder.com: The ABC's of PHP - Part 10 - The Final Installment (XML & Regex)
by Chris Cornutt June 03, 2009 @ 08:48:31
PHPBuilder.com finishes off their "ABCs of PHP" series today with this last tutorial covering a script to fetch the latest headlines from Slashdot and parse the resulting XML with regular expressions.
Well my loyal readers (and you must be loyal if you've made it this far). Here we are at the final installment of the 'ABC's of PHP' where we are going to put some of what we've learned over the past couple of months into practice. We're going to go step by step through a small script to read the latest headlines from Slashdot.org [...] As the feed is very simple however, I decided to simply just use 'preg_xxx' calls to elaborate on the material from part 9 on using reg-ex calls, if you where reading anything more complex then you would almost certainly want to use the proper XML functions.
The actual parsing is pretty simple - grabbing each story, date, time and title element from the XML content and pushing it all into an array. The result is a nice array you can loop through and display via the method of your choosing.
voice your opinion now!
regularexpression xml tutorial
Kevin Waterson's Blog: Introduction to PHP Regex
by Chris Cornutt September 09, 2008 @ 12:59:06
Kevin Waterson has posted an extensive tutorial to his site today giving a great look at regular expressions in PHP (and just regular expressions in general).
At its most basic level, a regex can be considered a method of pattern matching or matching patterns within a string. In PHP the most oft used is PCRE or "Perl Compatible Regular Expressions". Here we will try to decypher the meaningless hieroglyphics and set you on your way to a powerful tool for use in your applications. Do not try to understand all this in a single sitting. Instead, take in a little and come back as you grasp various concepts.
He starts with simple string matching, showing how to get values from the middle, end and beginning of it then moves on to the next more powerful step - using meta characters. He outlines these as well as sequences and modifiers. There's plenty of examples here so there's almost no chance of getting lost.
It's a great tutorial that I'd recommend to anyone who things regular expressions are "just too hard" or it looking to figure out their power.
voice your opinion now!
introduction tutorial regularexpression regex beginner
Debuggable Blog: String substitution using UUIDs
by Chris Cornutt August 22, 2008 @ 12:04:39
On the Debuggable blog, Felix Geisendorfer shows how to create a string parser that allows you to pull out parts of the string you don't currently want manipulated to be put back later.
If you've ever written any non-trivial String processing code, you've probably ran into the situation where you wanted to exclude certain parts of your string for a certain operation. Usually that would mean you have to tokenize your string, or adjust the operation you want to run so it doesn't affect the part of the string you want to exclude from it. Both of those solutions can be fairly time intensive so I was looking for a shortcut and found one.
He provides the code for this string substitution class, a method substitute() that matches based on a regular expression and, if found, stores the parts for later use.
voice your opinion now!
string substitution uuid manipulation regularexpression
|
Community Events
Don't see your event here? Let us know!
|