RE: help: regexp that works in applet but not in my code...

"Sam Wilson" <[email protected]> Wed, 23 Feb 2005 17:58:06 -0500
Newsgroups gmane.comp.jakarta.regexp.user
Message-ID <[email protected]>
By the way... by failing I mean that the call to re.match() is returning =
false.

Thanks again,

Sam Wilson

-----Original Message-----
From: Sam Wilson=20
Sent: Wednesday, February 23, 2005 5:57 PM
To: [email protected]
Subject: help: regexp that works in applet but not in my code...


Hey there,

I'm trying to make use of the RegExp library to parse the MAC address =
from the output of the Windows "ipconfig" program. I have an RE that I =
have tested using the Applet on your site and it is working fine. =
However, when I run the exact same RE in my code, it is failing.

Here's the text I'm searching (Apologize in advance if this messes with =
your MUA, but figured exactness was preferred...):

Host Name . . . . . . . . . . . . : xxx   Primary Dns Suffix  . . . . . =
. . : xxx   Node Type . . . . . . . . . . . . : Hybrid   IP Routing =
Enabled. . . . . . . . : No   WINS Proxy Enabled. . . . . . . . : No   =
DNS Suffix Search List. . . . . . : xxx                                  =
     xxxEthernet adapter Local Area Connection:   Connection-specific =
DNS Suffix  . :    Description . . . . . . . . . . . : Marvell Yukon =
88E8001/8003/8010 PCI Gigabit Ethernet Controller   Physical Address. . =
. . . . . . . : 00-11-2F-C9-0E-34   DHCP Enabled. . . . . . . . . . . : =
No   IP Address. . . . . . . . . . . . : 10.1.1.1   Subnet Mask . . . . =
. . . . . . . : 255.255.255.255   Default Gateway . . . . . . . . . : =
10.1.1.1   DNS Servers . . . . . . . . . . . : 10.1.1.1                  =
                     10.2.1.5   Primary WINS Server . . . . . . . : =
10.1.1.1   Secondary WINS Server . . . . . . : 10.1.1.1

Here's the RE I'm using:

([:xdigit:]{2})(\-[:xdigit:]{2}){5}

Here's the output I see from the applet:

Matches.

$0 =3D 00-11-2F-C9-0E-34
$1 =3D 00
$2 =3D -11
$3 =3D -2F
$4 =3D -C9
$5 =3D -0E
$6 =3D -34

Here's my code snippet:

    private static String getEthernetAddressFromIPConfig()
    {
        String ipconfig =3D getIPConfig();
        ServiceDebugger.println("Text to search: " + ipconfig);

        ServiceDebugger.println("Regular Expression to extract MAC: " + =
IPRE);
        RE re =3D new RE();
        try {
            re.setProgram(new RECompiler().compile(IPRE));
        }
        catch(RESyntaxException ex) {
            throw new RuntimeException("Failed to compile RE: " + =
ex.getMessage(), ex);
        }

        if(re.match(ipconfig)) {
            ServiceDebugger.println("MAC address found: " + =
re.getParen(0));
            return re.getParen(0);
        }
        else {
            ServiceDebugger.println("MAC not found.");
        }

        return null;
    }

I'm wondering if I'm not setting up the RE variable correctly. Also, I'm =
using the 1.3 version of the library. Let me know if any more info would =
be useful.

Thanks in advance,

Sam Wilson
Senior Software Engineer
610-941-4600 x228
610-941-4660 (fax)
[email protected]
http://www.ecount.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]