From: "Mauricio Fernández" Date: 2003-02-12T21:38:47+09:00 Subject: Re: String frustration On Wed, Feb 12, 2003 at 06:42:33PM +0900, Tim Kynerd wrote: > > No apologies necessary. I'm not 100% clear on this. > > Although I think I understand what's going on here, it leaves me wondering > what would be a better way to do what I need to do, if there is a better > way. > > The input file contains three tab-separated fields. The second field needs > to be able to contain an arbitrary number of newlines (which will be > realized as actual newlines, so to speak, when this field is later printed > out). > You want multi-line regex mode! >> a ="1\tsecond field\nwith newlines\nbla\nbla\tthird\n" => "1\tsecond field\nwith newlines\nbla\nbla\tthird\n" >> puts a 1 second field with newlines bla bla third => nil >> re = %r{([^\t]+)\t([^\t]+)\t([^\t]+)\n}m => /([^\t]+)\t([^\t]+)\t([^\t]+)\n/m >> a =~ re => 0 >> p $1, $2, $3 "1" "second field\nwith newlines\nbla\nbla" "third" => nil -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Linux: Where Don't We Want To Go Today? -- Submitted by Pancrazio De Mauro, paraphrasing some well-known sales talk