Given something like:
message.split(/\n.* at.* XXXXXXXX wrote:.*/m).first
This works if there is a match, but when there isn’t, it just returns all of message.
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.
If you’re trying to count the number of matches, then you’re using the wrong method.
splitis designed to take a string and chop it into bits, but as you’ve observed, if there aren’t any matches, then it returns the whole thing. I think you want to useString.scaninstead: