Jan Eden wrote:
Hi,

Hello,

I have lines like the following:

\begin{letter}{Name\\ Street\\ ZIP\\ Country}
\begin{letter}{Name\\ Street\\ ZIP}

To extract the info, I used

my ($data) = $file_content =~ /\\begin{letter}{(.+?)}/;
my ($name, $street, $zip, $country) = split /\\\\ /, $data;

But I wonder if this is also possible using a single regex.

This appears to do what you want:

$ perl -le'
@x = ( q[\begin{letter}{Name\\\ Street\\\ ZIP\\\ Country}],
       q[\begin{letter}{Name\\\ Street\\\ ZIP}]
     );
for ( @x ) {
    print;
    my ( $n, $s, $z, $c ) = /(?:\\begin{letter}{|)([^\\}]+)(?:}|\\+\s*)/g;
    print for $n, $s, $z, $c;
    }
'
\begin{letter}{Name\\ Street\\ ZIP\\ Country}
Name
Street
ZIP
Country
\begin{letter}{Name\\ Street\\ ZIP}
Name
Street
ZIP

$


John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to