Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex egrep报告“无效字符范围”_Regex_Unix_Character - Fatal编程技术网

Regex egrep报告“无效字符范围”

Regex egrep报告“无效字符范围”,regex,unix,character,Regex,Unix,Character,我想检查格式不正确的URL,因此我在网上找到了此正则表达式: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/ 但问题是,它向我输出消息“无效字符范围”。我想知道为什么 它不喜欢[\w-\],在[

我想检查格式不正确的URL,因此我在网上找到了此正则表达式:

/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/
但问题是,它向我输出消息“无效字符范围”。我想知道为什么

它不喜欢[\w-\],在[\w-\]中,它需要一个从wordcharacter到下划线的范围。 至少,在我的测试中,通过np++中的正则表达式(即perl风格)进行搜索,
这个小的子正则表达式已经出现了抱怨。

您的原始标题提到了egrep-x。-x选项似乎与问题无关。正如@Yunnosch所提到的,并添加了一些内容:所有连字符都需要放在括号中的末尾,这样可能就没问题了。所有连字符都需要放在括号中的末尾或开头。请注意,在ElasticSearch中,在Lucene正则表达式引擎中,-仅当位于括号表达式的开头时才被视为文字字符。