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.
What would /i at the end of gsub regex mean?
Вопрос
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|
Решение
Другие советы
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
Не связан с StackOverflow