From: Alex Gutteridge Date: 2007-08-05T17:52:43+09:00 Subject: Re: sgub stretching over several lines On 5 Aug 2007, at 16:41, Shai Rosenfeld wrote: > Jan Ask wrote: >> Hi, >> >> I am trying to do a in a replace a long (multiple line) string: >> >> string = string.gsub(/<h3 >> class="field-label>audience<\/h3> >> <div class="field-items> >> <div class="field-item>/, '') >> >> It somehow doesn't seem to work. >> >> I would like to know how to use a wildcard like '*', '%' or '...' >> like >> below: >> >> string = string.gsub(/<h ... tem>/, '') >> >> Thanks! >> Ask > >> string = string.gsub(/<h.*tem>/, '') > > .* > > # the . regexp wildcard means, 'any' character (space, symbol, letter) > # the * regexp wildcard is an operator saying: any regexp match before > me can appear 0 or more times: > > i.e, you get whatever character you want, however many times you want > it, between the '<h' string and the 'tem>' string. > hth > > happy sunday btw > -- > Posted via http://www.ruby-forum.com/. > .* won't match over multiple lines without the m modifier on the RegExp, which I think is the OP's problem: irb(main):021:0> string = "Hi\nJan\nAsk" => "Hi\nJan\nAsk" irb(main):022:0> string.gsub(/Hi.*Ask/,'Hi Jane Ask') => "Hi\nJan\nAsk" irb(main):023:0> string.gsub(/Hi.*Ask/m,'Hi Jane Ask') => "Hi Jane Ask" Alex Gutteridge Bioinformatics Center Kyoto University