From: Paul Lutus Date: 2006-09-19T01:26:17+09:00 Subject: Re: Regular expression for string.anotherstring Pit Capitain wrote: > Paul Lutus schrieb: >> Bart Braem wrote: >>> >>> I will try it with: >>> string =~ /^\w+\.\w+\z/ >>> >>> But is there a ruby operator to look for matches on the entire string? >> >> string =~ /^\w+\.\w+$/ >> >> Must match the entire string. Because of multiline issues, where that is >> a factor, you can always split on newlines in advance of this test to be >> sure you are matching the entire string unambiguously. > > This would be unnecessarily complex. Not really. ----------------------------------- #!/usr/bin/ruby s = "this is\na test\nstring." a = [] a << s.sub(/(^.*$)/,"\\1") a << s.sub(/(^.*\z)/,"\\1") a << s.sub(/(^.*$)/m,"\\1") a << s.sub(/(^.*\z)/m,"\\1") a.each do |s| puts "[#{s}]" end ----------------------------------- Output: [this is a test string.] [this is a test string.] [this is a test string.] [this is a test string.] > Just use Bart's regexp (with \z > instead of $). It matches the entire string. My point is that, if there are embedded linefeeds and they are an issue, they must be dealt with. Also, I don't immediately see a difference in behavior between \z and $, contrary to the documentation's specification that one matches the end of a line and the other matches the entire string. -- Paul Lutus http://www.arachnoid.com