On Jun 29, Babale said:
>I'm trying to print the content of a variable only if it contains three
>digits (1 2 3) and blank in between. Can anyone feature out why I don't
>get the right result with both expressions?
>@clean = split (/ +/, $clean);
> $arrlength = @clean;
> $cleanprint = join(" ", @clean);
This is kinda silly-looking. You don't NEED to squash multiple whitespace
to just one, do you? All that's doing is changing "12 45 78" into "12
45 78".
> print INPUT ("$cleanprint") if ($result = $cleanprint =~
>/([\d]{1,2}])(\s)\1\2\1/);
First, [\d] should just be \d. Second, you have an extra ] in there.
Second, it's requiring that the SAME digits be matched. That is, if it
were written as
/(\d{1,2})\s\1\s\1/
it would only be able to match things like "1 1 1" or "42 42 42", where
the number must be the same each time. Also, the {1,2} is allowing it to
match TWO digits. You said you wanted THREE digits.
I would suggest the following regex:
/\d\s+\d\s+\d/
Ta da.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]