From: ahoward Date: 2002-11-15T05:20:54+09:00 Subject: Re: regex help On Fri, 15 Nov 2002, Michael Campbell wrote: > Those aren't (mathematically) "regular" then, are they? (Granted, > existing 'regular' expressions aren't either with backreferencing.) in fact they are regular because the matching char is always known : it is either the same, or a match to a known mate. check out the oreily regex book, it's a really good read and has many examples of using dfa and nfa regexes to match, for example, matching comment paris (/* */) which is exactly like this problem now, it would be non-regular if you tried to make a single regular expression which would match ALL occurances mentioned since backreferencing would be required - maybe that's what you mean? i do agree that this type of method should not belong in a Regex class since a general method *would* appear to be non-regular, even if the collection of regexs where individually regular i think a String#delimscan method would be good, something like : class String @@delimscan_chars = { '\'' => '\'', '"' => '"', '(' => ')', '[' => ']', '{' => '}', '<' => '>', } def delimscan delim='"', escape='\\' o = delim[0] c = @@delimscan_chars[delim] c = c ? c[0] : o e = escape[0] w = [] b = 0 a = 0 n = 0 while ((b = self[n])) do case b when e n += 2 and next when o a = n n += 1 while ((b = self[n])) do case b when e n += 2 and next when c w << self[a..n] break end n += 1 end else; end n += 1 end return w end end if $0 == __FILE__ strings = [ %q("one"), %q("one" "two"), %q("o\"ne" "t\"wo"), %q("), %q(""), %q("""), %q(), ].each do |s| puts "TESTING #{s}" puts s.delimscan.inspect end strings = [ %q(), %q( wo>), %q(<), %q(<>), %q(<>>), %q(), ].each do |s| puts "TESTING #{s}" puts s.delimscan('<', '!').inspect end end -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================