Deb wrote:
> Hi,
>
> I'm having trouble coming up with a regular expression for $lines
> in @lines of this form:
>
> units = [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED]
> units = [EMAIL PROTECTED]
> units = [EMAIL PROTECTED] [EMAIL PROTECTED]
>
>
> ' ^units = ' is expected, all the rest is not - ie, one or more
> addrs, but they must be comma separated, not space, semi-colon or
> colon separated. So far, I've got:
>
> foreach my $line (@lines) {
> if ($line =~ /^units/)
> {
> $line =~ s/:/,/g;
> $line =~ s/;/,/g;
> }
> }
>
> The part I'm having trouble with is replacing the space(s) between
> the addresses. I don't want to touch any other whitespace. Only
> the space or spaces which might separate more than one address.
> It's okay if there's a comma and a space, but anything else needs
> to be replaced with a comma. There also doesn't have to be a space
> after the comma. Only the comma is necessary.
>
> I can't seem to find the right incantation to replace just those
> spaces.
>
Hi Deb.
Here's the way I'd do it. First check that the line starts with
'units' - whitespace - '=' - whitespace and strip it off in one
statement. Then you seem to be left with a number of emails
which are separated by any of colon, semicolon or whitespace, so
just split on a regex which says just that and rejoin the list with
commas.
foreach my $line (@lines) {
next unless $line =~ s/^units\s+=\s+//;
my @emails = split /[:;\s]+/, $line;
$line = join ',', @emails;
}
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]