What does "-mix:" mean in regex

What does "? -Mix:" mean in regex, is this also true in javascript / jQuery? If this is not valid, which is a suitable replacement.

Refresh . This is the full regular expression /(?-mix:^[^,;]+$)/

Used in javascript in chrome and I get the following error:

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

Note I found this useful: How to translate ruby โ€‹โ€‹regex into javascript? - (? i-mx: ..) and Rails 3.0.3

+4
source share
2 answers

Assuming a perl context, (?-mix) it will be

  • -m disable multiline matching
  • -i disable case insensitivity
  • -x disable extended regular expression spaces

See here: http://www.regular-expressions.info/modifiers.html

Not all regular expression flavors support this. JavaScript and Python apply all mode modifiers to the entire regular expression. They do not support syntax (? -Ismx), since disabling the option is pointless if mode modifiers are applied to all regular expressions. All options are disabled by default.

+9
source

Since you have made it clear now that the javascript context is here, I donโ€™t think javascript supports this flag syntax, so it complains that ^ is in the middle of the regular expression. Since you can never find the beginning of a match in the middle of a match, this makes an invalid regular expression.

In javascript, you specify flags outside the regular expression itself, for example:

 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 regular expression does not need the i flag.

What this particular regular expression is trying to do is tell you whether the string with which you match it matches all characters other than , and ; , and not empty.

+3
source

All Articles