简体   繁体   中英

preg_match(): Text range out of order on PHP Regex

I want to convert java regex to php regex. But I get error "- Text range out of order"

This is JAVA regex

"[^\\u0020-\\u007F\u011f\u00fc\u015f\u00f6\u00e7\u011e\u00dc\u015e\u0130\u00d6\u00c7\u0131]";

This is PHP regex

preg_replace("/[^\\x{0020}-\\x{007F}\\x{011f}\\x{00fc}\\x{015f}\\x{00f6}\\x{00e7}\\x{011e}\\x{00dc}\\x{015e}\\x{0130}\\x{00d6}\\x{00c7}\\x{0131}]/i","",".çşüiğıyuasdfaadsff");

I get following error "- Text range out of order"

Any Help?

By default, the regex engine interprets the input string and the regex as an array of bytes in PHP. You should get an error about the character value too large, since \\x{011f} or \\x{011e} are larger than 255 (the maximum value of one byte).

To match Unicode code points, rather than arbitrary byte sequences, use u flag to turn on UTF mode.

$re = '~[^\x{0020}-\x{007F}\x{011f}\x{00fc}\x{015f}\x{00f6}\x{00e7}\x{011e}\x{00dc}\x{015e}\x{0130}\x{00d6}\x{00c7}\x{0131}]~u';

RegEx Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM