# Can you make just part of a regex case-insensitive?

I've seen great deals of instances of making a whole normal expression instance - aloof. What I'm questioning is having simply component of the expression be instance - aloof.

As an example, allow is claim I have a string similar to this:

fooFOOfOoFoOBARBARbarbarbAr


What if I intend to match all events of "foo" no matter instance yet I just intend to match the upper - instance "BAR"s?

The excellent remedy would certainly be something that functions throughout regex tastes yet I'm interested in listening to language - details ones too (Thanks Espo)

Edit

The link Espo gave was really handy. There is an example in there concerning transforming modifiers on and also off within the expression.

For my contrived instance, I can do something similar to this:

(?i)foo*(?-i)|BAR


that makes the suit instance - aloof for simply the foo section of the suit.

That appeared to operate in the majority of regex executions other than Javascript, Python, and also a couple of others (as Espo stated).

The large ones that I was questioning (Perl, PHP,. NET) all assistance inline setting adjustments.

111
2022-06-08 04:52:15
Source Share

Perl allows you make component of your normal expression instance - aloof by utilizing the (? i pattern modifier.

Modern regex tastes permit you to use modifiers to only component of the normal expression. If you insert the modifier (? ism) in the center of the regex, the modifier just relates to the component of the regex to the right of the modifier. You can switch off settings by preceding them with a minus indicator. All settings after the minus indicator will certainly be switched off, Eg. (? i - sm) activates instance ignorance, and also switches off both solitary - line setting and also multi - line setting.

Not all regex tastes sustain this. JavaScript and also Python use all setting modifiers to the whole normal expression. They do not sustain the (? - ismx) syntax, given that switching off an alternative is meaningless when setting modifiers relate to the entire normal expressions. All alternatives are off by default.

You can promptly examine just how the regex taste you are making use of takes care of setting modifiers. The regex (? i) te (? - i) st needs to match examination and also TEst, yet not examination or TEST.

94
2022-06-08 05:02:21
Source

You could make use of

(?:F|f)(?:O|o)(?:O|o)


The?: in the brackets in.Net suggests it is non - recording, and also simply made use of to organize the regards to the|(or) declaration.

7
2022-06-08 04:55:08
Source

What language are you making use of? A typical means to do this would certainly be something like/ ([Ff] [Oo] 2 |BAR)/ with instance level of sensitivity on, yet in Java, as an example, there is an instance level of sensitivity modifier (? i) that makes all personalities to the right of it instance aloof and also (? - i) which compels level of sensitivity. An instance of that Java regex modifier can be located here.

6
2022-06-08 04:55:01
Source

Unfortunately syntax for instance - aloof matching is not usual. In.NET you can make use of RegexOptions.IgnoreCase flag or ? i modifier

7
2022-06-08 04:54:59
Source