ruby - What do `?i` and `?-i` in regex mean? -


could explain (?i) , (?-i) wrapping word in regex mean?

(?i)test(?-i) 

i tested , matches test, test, , test. have never seen before. ? before i mean? saw here.

(?i) starts case-insensitive mode

(?-i) turns off case-insensitive mode

more information @ "turning modes on , off part of regular expression" section of page:

modern regex flavors allow apply modifiers part of regular expression. if insert modifier (?ism) in middle of regex, modifier applies part of regex right of modifier. can turn off modes preceding them minus sign. modes after minus sign turned off. e.g. (?i-sm) turns on case insensitivity, , turns off both single-line mode , multi-line mode.

not regex flavors support this. javascript , python apply mode modifiers entire regular expression. don't support (?-ismx) syntax, since turning off option pointless when mode modifiers apply whole regular expressions. options off default.

you can test how regex flavor you're using handles mode modifiers. regex (?i)te(?-i)st should match test , test, not test or test.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -