Reputation: 991
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?
Upvotes: 0
Views: 252
Reputation: 786359
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';
Upvotes: 2