Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a regex I could use that would capture OID strings and not IP strings?

(i.e. 1.3.6.4.1.68.2.3.5 and not 255.255.255.255)

Thanks

Replies are listed 'Best First'.
Re: RegEx needed
by Limbic~Region (Chancellor) on Sep 05, 2003 at 13:49 UTC
    Anonymous Monk,
    I am betting you will be surprised to find out that not all OIDs are the same. OID is defined as an Object Identifier - a string of digits seperated by periods with the most signficant digits being found to the left and working right towards least significant.

    That is where the similarities end. I did various searches on CPAN and Google looking for an RFC or a pre-existing regex to do what you were looking for. I found lots of OIDs that didn't look like your example. So to answer your question further - you will have to specificy exactly which kind of OID you are using (application/log that has the OIDs in question).

    Cheers - L~R

Re: RegEx needed
by Abigail-II (Bishop) on Sep 05, 2003 at 12:05 UTC
    Probably. How do OID strings look like?

    Abigail

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: RegEx needed
by jadev (Initiate) on Sep 05, 2003 at 12:20 UTC
    $ip_pattern = qr((?:(?:[01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.){3}(?:[01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]));

    This matches only IP addresses. There's one caveat: 0.0.0.0 is matched too.

    Use it like this:

    if ($oid =~ /^(?:\d+\.)+\d+$/ and $oid !~ /^$ip_pattern$/o) { blah blah blah }

    janitored by ybiC: Balanced <code> tags around code sample, as per Monastery convention