From: Robert Klemme Date: 2005-02-25T02:00:02+09:00 Subject: Re: regexp help sought schrieb im Newsbeitrag news:1109263535.280360.203760@g14g2000cwa.googlegroups.com... > Hey All, > > I'm trying to parse lines from my text editor's config file, which look > like this (pls watch for line wrap--there is one line per language, > starting with /L<>): > > /L1"SAS" Line Comment = * Block Comment On = /* Block Comment Off = */ > Block Comment On Alt = * Block Comment Off Alt = ; Nocase File > Extensions = SAS > /L2"Visual Basic" Line Comment = ' File Extensions = BAS FRM CLS VBS > CTL WSF > /L4"HTML" Nocase Noquote HTML_LANG Block Comment On = Block Comment On Alt = <% Block Comment Off Alt = %> > String Chars = "' File Extensions = HTM HTML ASP SHTML HTT HTX JSP > /L11"Ruby" Line Comment Num = 2# Block Comment On = =begin Block > Comment Off = =end String Chars='" Escape Char = \ File Extensions = RB > RBW > > I'm trying to write a method for extracting the comment markers & their > types (line/block & on/off). Regexps seemed the obvious tool, and I > eventually came up with this one: > > c = Regexp.new("(Line|Block) Comment (On |Off |On Alt |Off Alt)*= > ([^\s\t\r\n\f]+) ") > > This is working well so far, except that it only grabs out the first > type of comment in each line. I'd hoped that I could make it get all > the comment types by putting an additional set of parens and a + > quantifier around the whole expression: > > c = Regexp.new("((Line|Block) Comment (On |Off |On Alt |Off Alt)*= > ([^\s\t\r\n\f]+))+ ") > > But that just seems to break it--that version doesn't capture anything. > > Anybody got a clue for me? I'm using v1.8 on windows. My code is > below. (And again, pls watch for line wrapping). You want String#scan matches = line.scan(re) or line.scan(re) do |match| .... end Kind regards robert