What does "?-mix:" mean in regex, also is this valid in javascript/jQuery? If it's not valid, what is an appropriate substitute.
“?-mix:”在正则表达式中的含义是什么,这在javascript / jQuery中是否有效?如果它无效,那么什么是合适的替代品。
Update: This is the full regex /(?-mix:^[^,;]+$)/
更新:这是完整的正则表达式/(? - mix:^ [^,;] + $)/
Its used in javascript in chrome, and I'm getting the following error:
它在chrome中使用javascript,我收到以下错误:
Uncaught SyntaxError: Invalid regular expression: /(?-mix:^[^,;]+$)/: Invalid group
未捕获的SyntaxError:无效的正则表达式:/(? - mix:^ [^,;] + $)/:无效的组
Note: I found this helpful: How to translate ruby regex to javascript? - (?i-mx:..) and Rails 3.0.3
注意:我发现这有用:如何将ruby正则表达式转换为javascript? - (?i-mx:..)和Rails 3.0.3
2 个解决方案
#1
9
Assuming perl context, (?-mix)
this would
假设perl上下文,(? - mix)就可以了
- -m disable multiline matching
- -i disable case insensitive matching
- -x disable extended regex whitespace
-m禁用多行匹配
-i禁用不区分大小写的匹配
-x禁用扩展的正则表达式空格
See here: http://www.regular-expressions.info/modifiers.html
见这里:http://www.regular-expressions.info/modifiers.html
Not all regex flavors support this. JavaScript and Python apply all mode modifiers to the entire regular expression. They don't support the (?-ismx) syntax, since turning off an option is pointless when mode modifiers apply to the whole regular expressions. All options are off by default.
并非所有正则表达式都支持这一点。 JavaScript和Python将所有模式修饰符应用于整个正则表达式。它们不支持(?-ismx)语法,因为当模式修饰符应用于整个正则表达式时,关闭选项是没有意义的。默认情况下,所有选项均已关闭
#2
3
Since you've now made it clear that the context here is javascript, I don't think javascript supports that flag syntax so it's complaining about ^
being found in the middle of a regex. Since you can never find the start of a match in the middle of a match, this makes an invalid regex.
既然你现在已经清楚这里的上下文是javascript,我不认为javascript支持那个标志语法,所以它抱怨在正则表达式中找到^。由于你无法在匹配中找到匹配的开头,因此这会产生无效的正则表达式。
In javascript, you specify flags outside the regex itself such as:
在javascript中,您指定正则表达式本身之外的标志,例如:
var re = /^[^,;]+$/mi;
or as an argument like this:
或者作为这样的论点:
var re = new RegExp("^[^,;]+$", "mi");
The x
flag is not supported in javascript and this particular regex does not need the i
flag.
javascript中不支持x标志,这个特殊的正则表达式不需要i标志。
What this particular regex is trying to do is to tell you whether the string you are matching it against contains all characters other than ,
and ;
and is not empty.
这个特殊的正则表达式试图做的是告诉你你匹配的字符串是否包含除了和之外的所有字符;而且不是空的。
#1
9
Assuming perl context, (?-mix)
this would
假设perl上下文,(? - mix)就可以了
- -m disable multiline matching
- -i disable case insensitive matching
- -x disable extended regex whitespace
-m禁用多行匹配
-i禁用不区分大小写的匹配
-x禁用扩展的正则表达式空格
See here: http://www.regular-expressions.info/modifiers.html
见这里:http://www.regular-expressions.info/modifiers.html
Not all regex flavors support this. JavaScript and Python apply all mode modifiers to the entire regular expression. They don't support the (?-ismx) syntax, since turning off an option is pointless when mode modifiers apply to the whole regular expressions. All options are off by default.
并非所有正则表达式都支持这一点。 JavaScript和Python将所有模式修饰符应用于整个正则表达式。它们不支持(?-ismx)语法,因为当模式修饰符应用于整个正则表达式时,关闭选项是没有意义的。默认情况下,所有选项均已关闭
#2
3
Since you've now made it clear that the context here is javascript, I don't think javascript supports that flag syntax so it's complaining about ^
being found in the middle of a regex. Since you can never find the start of a match in the middle of a match, this makes an invalid regex.
既然你现在已经清楚这里的上下文是javascript,我不认为javascript支持那个标志语法,所以它抱怨在正则表达式中找到^。由于你无法在匹配中找到匹配的开头,因此这会产生无效的正则表达式。
In javascript, you specify flags outside the regex itself such as:
在javascript中,您指定正则表达式本身之外的标志,例如:
var re = /^[^,;]+$/mi;
or as an argument like this:
或者作为这样的论点:
var re = new RegExp("^[^,;]+$", "mi");
The x
flag is not supported in javascript and this particular regex does not need the i
flag.
javascript中不支持x标志,这个特殊的正则表达式不需要i标志。
What this particular regex is trying to do is to tell you whether the string you are matching it against contains all characters other than ,
and ;
and is not empty.
这个特殊的正则表达式试图做的是告诉你你匹配的字符串是否包含除了和之外的所有字符;而且不是空的。