News Feed
Sections




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

Stoimen Popov's Blog:
preg_match Give Names to the Matches
July 06, 2010 @ 11:01:48

In a quick post to hos blog today Stoimen Popov points out a handy feature of the preg_match function in PHP (in PHP 5.2.2 and higher) to be able to name the results of the regular expression match.

In PHP 5.2.2+ you can name the sub patterns returned from preg_match with a specific syntax. [...] This is extremely helpful, when dealing with long patterns. [...] Although it may look difficult to maintain, now you can simply name the sub patterns of preg_match and to call them with their associative array keys. This is more clear when writing code and it's definitely more maintainable.

The key is to use a special syntax as a part of the expression's pattern. This replaces the numeric keys of the matches with values you define, making it simpler to use the results (instead of having to work with numbers that don't match much of anything). Code and expression examples are included.

0 comments voice your opinion now!
named result match pregmatch regularexpression


blog comments powered by Disqus

Similar Posts

Michael Nitschinger's Blog: Writing a simple lexer in PHP

PHPClasses.org: Lately in PHP Ep. 6 - Unusual Site Speedup Techniques, Named params & Annotations

Sean Coates' Blog: PHP Pie?

Reinhold Weber's Blog: 40 signs you really are a lousy PHP programmer

The Northclick Blog: A comma is a comma is a comma...or is it?


Community Events





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


tips interview series conference threedevsandamaybe introduction bugfix zendserver language release framework deployment symfony podcast code voicesoftheelephpant list laravel community api

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