Pergunta

I am starting on Ruby and referring to "Begining Ruby From Novice to professional" book. Something that I wasn't able to figure out is the /i at the end of this regex means..

text.gsub(/\b(You|Me|My|Your)\b/i) do |x|
Foi útil?

Solução

The i modifier is used to perform case-insensitive matching. By using this modifier, letters in the pattern match both upper and lower case. Be sure to check out the Regexp documentation.

Outras dicas

Thats case insensitive
it means no matter if the sentence or even the letter are upper or lower case

like

/foobar/i 

will match for any variation of upper and lower cases of foobar

you can define in some languages (?i:word)
if you want to match just F and B you can or any other letter or word

(?i:f)oo(?i:b)ar

will match for FooBar or foobar

i - means 'case insensetive'.

so /a/i matches "A"

You can be interested reading this and play with Rubular.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top