News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

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


blog comments powered by Disqus

Similar Posts

DevShed: Introducing the Strategy Pattern

Brandon Savage's Blog: The Registry Pattern Reexamined

International PHP Magazine: Poll Question: The Biggest Advantage of PHP 5 is?

LispCast.com: An interesting analysis of why PHP is so popular

PHPClasses.org: Lately in PHP Podcast #46 - "Is the Hack Language Going to Replace PHP?"


Community Events

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


list project application series community yii2 interview framework podcast voicesoftheelephpant language laravel api example introduction composer symfony php7 part2 opinion

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