Forum: Ruby grep a block of code

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
236de671fc49b3eca5bf426656aa15ab?d=identicon&s=25 beny 18241 (beny18241)
on 2009-05-07 13:35
Hi


Lately someone gave me a task, to grep from csv file but a block of
code.
How to do it ?

for example

<tag>
2
3
4
5
</tag>


How to use grep to give me all form file wich start with <tag> and end
with </tag>

I've tried that way..

puts File.readlines(ARGV[0]).grep(/<tag> * <\/tag>/)

Please help
4feed660d3728526797edeb4f0467384?d=identicon&s=25 Bill Kelly (Guest)
on 2009-05-07 14:05
(Received via mailing list)
From: "Maciej Pindela" <beny18241@gmail.com>
>
> I've tried that way..
>
> puts File.readlines(ARGV[0]).grep(/<tag> * <\/tag>/)

puts ARGF.read.scan(/<tag>.*?<\/tag>/m)


Regards,

Bill
236de671fc49b3eca5bf426656aa15ab?d=identicon&s=25 beny 18241 (beny18241)
on 2009-05-08 11:00
Bill Kelly wrote:
> From: "Maciej Pindela" <beny18241@gmail.com>
>>
>> I've tried that way..
>>
>> puts File.readlines(ARGV[0]).grep(/<tag> * <\/tag>/)
>
> puts ARGF.read.scan(/<tag>.*?<\/tag>/m)
>
>
> Regards,
>
> Bill

Thanks that's works
This topic is locked and can not be replied to.