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.
beny 1. (Guest)
on 2009-05-07 15: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
Bill K. (Guest)
on 2009-05-07 16:05
(Received via mailing list)
From: "Maciej Pindela" <removed_email_address@domain.invalid>
>
> I've tried that way..
>
> puts File.readlines(ARGV[0]).grep(/<tag> * <\/tag>/)

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


Regards,

Bill
beny 1. (Guest)
on 2009-05-08 13:00
Bill K. wrote:
> From: "Maciej Pindela" <removed_email_address@domain.invalid>
>>
>> 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.