Jeff Schwab
4/28/2006 5:47:00 PM
David Alm wrote:
> I'm new to both Ruby and RegExp.
>
> I'm wanting to do a string sub in lines of a file but have the match
> criteria for gsub be case-independent. The only think I could think of was
> to upcase the whole thing:
>
> content = File.readlines( x ).collect! { |line|
> if ( line =~ /someLineCriteria.*$/ )
> line.upcase!.gsub(/SOME_GSUB_CRITERIA/, $string_to_sub )
> else
> line
> end
> }
>
> But I would prefer not to have to upcase it all, and have the RE match
> "SomE_Gsub_CRITeria" or any similar combination of upper/lower case.
>
> Thanks in advance.
After the last slash of the regex literal, add the modifier "i":
/someLineCriteria.*$/i