Stefano Crocco
11/28/2008 3:39:00 PM
Alle Friday 28 November 2008, jackster the jackle ha scritto:
> I need to be able to match all data before the word "Total:" and then I
> will replace it with "" using gsub.
>
> Here is the text:
>
> C
> THIS IS THE TEXT I WANT TO MATCH ON
> and this.....
> and this too...
> and there could be this line too but the following line is always there.
> Total:
> But I need to keep
> all text after
> the text "Total:"
>
>
> I was thinking that I would somehow use a regexp index but I'm not sure
> how to do it.
>
> thanks
> jackster
This should work:
str = <<EOS
line1
line2
line3
Total: text
line4
EOS
new_str = str.sub(/.*^Total:/m,'')
Note the m after the closing slash of the regexp. It means that the regexp is
multiline, that is it means that newline characters (\n) should be treated as
any other character (in particular, the dot will also match them).
I hope this helps
Stefano