Question

I this RegEx for matching whitespaces in Unicode:

/^[\pZ\pC]+|[\pZ\pC]+$/u

I'm not even sure of what it does, but it seems to work. Now, in this case, which function applies better and why?

$str = preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $str);

or

$str = mb_ereg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $str);
Was it helpful?

Solution

The first one works. The second one doesn't.

Tried it out again, mb_ereg_replace doesn't actually support those Unicode char escapes. And it doesn't use regex delimiters. (See Oniguruma)

preg_replace uses the PCRE regex engine, which supports both.


Anyway, there is no such thing as a "better" application. It's either functioning, or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top