In Ruby, how can I check if some file contains some word? I’ve tried this:
foo = File.open('some-file', 'r').read
foo.index(/^word$/)
But this won’t work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Remeber that
^matches against the beginning of a line, and$matches against the end of a line. So if you search for^xyz$you are really searching for eitherxyz\n(beginning of file) or\nxyz\n(somewhere in the middle of the file). No other strings will match.