admin管理员组

文章数量:1301528

What does "?-mix:" mean in regex, also is this valid in javascript/jQuery? If it's not valid, what is an appropriate substitute.

Update: This is the full regex /(?-mix:^[^,;]+$)/

Its used in javascript in chrome, and I'm getting the following error:

Uncaught SyntaxError: Invalid regular expression: /(?-mix:^[^,;]+$)/: Invalid group

Note: I found this helpful: How to translate ruby regex to javascript? - (?i-mx:..) and Rails 3.0.3

What does "?-mix:" mean in regex, also is this valid in javascript/jQuery? If it's not valid, what is an appropriate substitute.

Update: This is the full regex /(?-mix:^[^,;]+$)/

Its used in javascript in chrome, and I'm getting the following error:

Uncaught SyntaxError: Invalid regular expression: /(?-mix:^[^,;]+$)/: Invalid group

Note: I found this helpful: How to translate ruby regex to javascript? - (?i-mx:..) and Rails 3.0.3

Share edited May 23, 2017 at 12:32 CommunityBot 11 silver badge asked Apr 26, 2013 at 14:22 user160917user160917 9,3504 gold badges54 silver badges63 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 10

Assuming perl context, (?-mix) this would

  • -m disable multiline matching
  • -i disable case insensitive matching
  • -x disable extended regex whitespace

See here: 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.

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 plaining 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.

In javascript, you specify flags outside the regex itself such as:

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.

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.

本文标签: javascriptWhat does quotmixquot mean in regexStack Overflow