From: Warren Brown Date: 2005-04-06T23:58:15+09:00 Subject: Re: Regular expression mismatch ? Han, > Why does the following: > > s = "aaa aaa\n\n\nbbb bbb" > puts(s =~ /^\s+$/) > > produce: 8 (instead of nil) ? Because /^/ matches the beginning of a line (not the beginning of the string), and /\s/ matches whitespace, which includes newlines (\n). So the first place in the string where the beginning of a line is followed by one or more whitespaces is at position 8. > (If I put in only 2 newlines, it's fine). With only two newlines, the /$/ prevents the match, since there are "b"s following the newline. I hope this helps. - Warren Brown