Regular expression word boundary does not work in utf8 on some servers

I have a strange problem. consider this short code:

<?php $reg = '/(?<!\pL)(test)(?!\pL)/u'; $text='This is a test text'; $replace = 'test_replaced'; $newtext = preg_replace($reg, $replace, $text); echo "Error: ".preg_last_error()."\nResult: ".$newtext."\n"; ?> 

On some servers, UTF8 bounds does not work. I get

 Error: 0 Result: 

In most servers, everything works fine:

 Error: 0 Result: This is a test_replaced text 

It seems that the problem is related to word boundary when I use \b and the code works.

Both servers use php 5.2.13. Any clues what might be wrong and how to get around this?

+3
php regex
Jan 24 '11 at 12:22
source share
1 answer

The comment here seems to suggest that PCRE needs to be compiled with --enable-unicode-properties .

+3
Jan 24 '11 at 12:36
source share



All Articles