Skip to content
Advertisement

Within a regex is xhh same as x{hh}?

Within a regex seems that it is the same:

if(preg_match('/x{61}/',"a",$m)) //Same as just x61
    print_r($m);

But if you make echo both apart.

echo "x61";//Display a
echo "x{61}";//Display x{61}

Note: Not confuse with the '/x{0000}/u'

I don’t see info about that and I’m not sure which to use.

Advertisement

Answer

pcre has its own escape rules, which are different from those in php. From http://www.pcre.org/pcre.txt

Characters whose value is less than 256 can be defined by either of the two syntaxes for x. There is no difference in the way they are han- dled. For example, xdc is exactly the same as x{dc}.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement