简体   繁体   English

preg_match():PHP Regex上的文本范围混乱

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

I want to convert java regex to php regex. 我想将Java regex转换为php regex。 But I get error "- Text range out of order" 但我收到错误“-文本范围混乱”

This is JAVA regex 这是JAVA正则表达式

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

This is PHP regex 这是PHP正则表达式

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. 默认情况下,正则表达式引擎将输入字符串和正则表达式解释为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). 由于\\x{011f}\\x{011e}大于255(一个字节的最大值),因此您会收到有关字符值太大的错误。

To match Unicode code points, rather than arbitrary byte sequences, use u flag to turn on UTF mode. 要匹配Unicode代码点,而不是任意字节序列,请使用u标志打开UTF模式。

$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 正则演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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