On 27 May 2013 18:42, Thomas Worthington <[email protected]> wrote:
> I've got a string which is the header section of an email. I have a regex
> which will split a header field name from its data (ie, "From:
> [email protected]" becomes "From" and "[email protected]") but some header lines are
> long and have been continued by inserting a newline and one or more
> spaces. Before splitting the fields I need to undo these continuations by
> deleting these combinations of a newline followed by some whitespace.
>
> This would certainly be trivial in Perl or any of the normal Linux regex
> engines but I've spent hours on this today, equipped with the PBE2
> chapter, and got nowhere.
>
> How do I do this in Pharo?
trimBlock := [:string |
| lines |
lines := string lines.
lines collect: #trimmed ].
trimBlock value: 'Header1: fooo
Header2: barrr
Header3: zork'
=>
#('Header1: fooo' 'Header2: barrr' 'Header3: zork')
>
> Thanks,
>
> Thomas
>
--
Best regards,
Igor Stasenko.