From: ahoward Date: 2003-06-24T06:40:54+09:00 Subject: Re: can't find appropriate regexp On Mon, 23 Jun 2003, Simon Strandgaard wrote: > Is there anyone who know how to do the *reject* thing ? (?!pattern) rejects. but as to the original problem: the problem is that odd numbered escapes *contain* even numbered escapes and vise versa, so you also need some sort of anchor ([^\\], ^, \A) etc. but that too becomes problematic... this seems to work because it handle odd number escapes contained in even numbered escapes from being accepted - it other words it forces odd numbered escapes to standalone : ~/eg/ruby > cat quotematch.rb #!/usr/bin/env ruby tests = DATA.readlines re = %r/ ["] (?: [^\\](?:[\\][\\])*[\\]["] | # prevent even escaped quotes # from being accepted for containing # and odd escaped quote (?:[\\][\\])*[\\]["] | # accept odd escaped quotes (?:[\\])+[^"]? | # accept any escape sequence which # does not escape a quote (?:[^\\"]+) # accept anthing neither quote nor escaped )* ["] /iomx tests.map{|t|f=nil;t.scan(re).map{|m| print"[#{m}] ";f=1;};puts if f} __END__ foo "foobar"; bar "foo" "bar"; a "foo \"bar\""; b "foo \\"bar\\""; c "foo \\\"bar\\\""; d "foo \\\\"bar\\\\""; e "foo \t" "\t bar" e "foo \\t" "\\t bar" ~/eg/ruby > ruby quotematch.rb ["foobar"] ["foo"] ["bar"] ["foo \"bar\""] ["foo \\"] [""] ["foo \\\"bar\\\""] ["foo \\\\"] [""] ["foo \t"] ["\t bar"] ["foo \\t"] ["\\t bar"] -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ara.t.howard@noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 | ~ > ruby -e 'p(%.\x2d\x29..intern)' ====================================