Le 07/07/2011 13:44, Stan Hoeppner a écrit :
> On 7/7/2011 5:58 AM, /dev/rob0 wrote:
>> On Thu, Jul 07, 2011 at 03:36:02AM -0500, Stan Hoeppner wrote:
>>> I received a request to ignore IPv4 addresses as well in order to
>>> improve performance. But given the extensive IF loops it seems
>>> we'd only save something like a few picoseconds of CPU time (<30
>>> expressions processed). If that's actually critical I could add
>>> something like
>>>
>>> /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ DUNNO
>>>
>>> Crude testing with postmap -q shows this matches only a naked
>>> dotted quad, but I'd rather not unleash it without more thorough
>>> testing, or confirmation from resident regex gurus that this will
>>> work as intended. Many rDNS strings contain a dotted quad, so we
>>> want to return DUNNO only for a naked dotted quad.
>>
>> The anchors at both ends mean you are safe. You start with ^ and end
>> with $, so nothing else can sneak in between those.
>>
>> A simpler expression to accomplish the same thing:
>> /^[0-9\.]$/ DUNNO
>> In English, that says: match a string which contains nothing but
>> numerals and dots. It matches nonsense strings such as "...", but
>> would be safe as per your intent to only match bare IP addresses.
>
> With that being right anchored, the last character it attempts to match
> is a dot, no? See a problem there?
no. the [] means anything inside. so [ab] means either 'a' or 'b'. and
[0-9\.] means a "digit or dot". so
/^[0-9\.]$/
is equivalent to
any string formed with digits and/or dots
with pcre; you can shorten this to
/^[\.\d]+$/
but for your fqrdns, there is no point being that precise. it's enough to do
/(:\d$)/ DUNNO
this means ignore anything that ends with a digit or contains a ':'.
this helps avoiding IPv4 and IPv6 addresses. and more preciesily, your
fqrdns isn't supposed to catch any rdns that contains a ':' or ends with
a digit, is it?