Hi,

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. The first three 
parts are simple, but the optional fourth field seems complicated to capture.

 Before I thought of splitting the whole string after capturing it, I tried to 
use two regexes, one to grab the mandatory fields, a second one to grab the 
optional country. The second one is simple, the first one looked like:

($name, $street, $zip) = $file_content =~ /\\begin{letter}{(.+?)\\\\ (.+?)\\\\ 
([^//]+?)}/;

But this obviously captures the street and the zip in $street if country is 
present, as it still has country for the third parentheses.

As I already solved the problem in a different, this is not strictly necessary, 
I was just wondering if there's a regex way to do it and if it is even possible 
in a single regex.

Thanks,

Jan
-- 
Remember: use logout to logout.

--
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