David Budd wrote:
I thought this was working, but my logs just showed a case where it
seems not to do what I want.
Why does:
$OK_body=($body=~/library\s*?card\D*?(\d{7})\D/i) ;
Not become true when $body contains:
Library Card: 0240742
i'd bet that it passes when you have some whitespace after the number
and fails when it doesn't. thats a common problem and can be hard to trace.
in any event, your ending \D *requires* a non-digit character to
immediately follow the number. since your example failed, it must be
terminating the line. adding a ? or * to the \D will not behave as (I
believe) you intend, i.e. it will not filter out numbers with 8 or more
digits
so IF your string always terminates the line (with or without
whitespace), this will require exactly seven digits and not care whether
or not whitespace follows:
$OK_body = ($body =~ /library\s*card\s*:?\s*(\d{7})\s*$/i)
However... if the "library card: #" string does not always terminate
the line and/or if you need to allow the possibility of non-digit
characters immediately after the 7-digit number (example, library card:
1234567MORE_STUFF), then you will need to use a word boundary:
$OK_body = ($body =~ /library\s*card\s*:?\s*(\d{7})\D*\b/i)
and by the way, *? is redundant.
* means zero or more.
? means zero or one.
--rob
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs