News Feed
Jobs Feed
Sections

Recent Jobs

News Archive
SitePoint PHP Blog:
Tokenization using regular expression sub patterns
January 18, 2008 @ 11:15:49

On the SitePoint PHP blog there's a new post from Harry Fuecks talking about a replacement method using token that works a bit better than the typical regular expression method.

Promtped by a real world example, one often-overlooked feature of most regular expressions engines is how subpatterns can useful to whip up tokenizers relatively easily. The problem? I needed to match the word any of the words "Canton", "Region" or "Group" in a string and perform a follow up action depending on which matched.

His ultimate solution used a set of preg_match generated tokens to do the replaces a bit more reliably. It also makes it easy for other scripts (like his Python example) to use them too.

0 comments voice your opinion now!
regularexpression pattern token replace



Similar Posts

DevShed: Introducing the Facade Pattern in PHP 5

Dikini.net: Rewriting macros - the peculiar case of php

Sean Coates' Blog: PHP Pie?

Debuggable Blog: String substitution using UUIDs

DevShed: Iterators in the Simplest Sense - An Accessible Implementation in PHP 4


Community Events







Don't see your event here?
Let us know!


framework PHP5 book example code release releases zendframework zend developer mysql database application PEAR conference job cakephp ajax package security

All content copyright, 2008 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework