0

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?

3
  • Where do you get this error? When pasting the regex string into regex101.com? Commented Jul 3, 2015 at 7:25
  • Try adding the u modifier after i Commented Jul 3, 2015 at 7:26
  • Not sure why you get that error: On ideone, I get this PHP Warning: preg_replace(): Compilation failed: character value in \x{} or \o{} is too large at offset 26 in /home/ivJ7iQ/prog.php on line 3 ideone.com/lbZv74 Commented Jul 3, 2015 at 8:18

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

In PHP use this regex: Why should OP use his regex? What did you changed and why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.