views:

42

answers:

2

Hello,

I'm using two different version of php on two different OS's.

One is 5.2.9 running on windows (wamp).

One is 5.2.6 running on CentOS 5 (lamp).

Regex involving group names works on the Windows one but not on the CentOS.

Such example would be /^field_(?<myname>.+)/

Is this an OS issue? Or one with the way PHP was build?

Thanks,

A: 

Which regex functions do you use? PHP has ereg and preg, and the preg regular expression behaves like perls regular expression, and should behave the same on all OSes.

Marius
preg, I'm afraid.
Dave
+1  A: 

Most regex functions available in PHP derive back to libpcre, that library has had a turbulent history in the couple years in response to some security issues, the fixes for those issues change semantics. When building PHP by default it uses a bundled libpcre, when that changes it is noted in the changelog here: http://www.php.net/ChangeLog-5.php . Some distributions or if you compile yourself may cause php to use an external libpcre which will have the semantics of that version.

There is no good solution except that so far things tend to break forward, meaning if your regex works with the latest version it tends to work inl historical versions, the reverse, as I pointed out, is not true.