Solved

Regular expression to Extract mac address and wireless network id in java

Posted on 2010-11-23
4
948 Views
Last Modified: 2012-06-21
Hi Experts:

I need an expression to extract mac address and wireless network id:

00-1E-4C-32-DA-2E:ssid1

Right now I use the following code (I have posted the code fragment)

    Pattern pattern = Pattern.compile("(.*):(.*)");
      Matcher matcher = pattern.matcher(Csid);
      if(matcher.matches())
      {
         System.out.print("Key:");
         bssid = matcher.group(1);
         System.out.println(matcher.group(1));
         System.out.print("Value:");
         System.out.println(matcher.group(2));

Csid is the String contain mac address and ssid.

But this code does not work when there is no wireless network id present, for example:

00-1E-4C-32-DA-2E

Please give me an expression to parse and extract both and the code fragment.
00-1E-4C-32-DA-2E:ssid1
or
00-1E-4C-32-DA-2E

It should extact both.

Best Regards,

Sunnybrad
0
Comment
Question by:sunnybrad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 34199385
Try the below. If groupCount == 2, only collect group 2 if it's not null
Pattern p = Pattern.compile("((?:[0-9A-F]{2}-){5}[0-9A-F]{2})(:[^ ]+)*");

Open in new window

0
 

Author Comment

by:sunnybrad
ID: 34199442
Hi:

Thanks for the comment, please give some comments whats groupcount. Shall I fir this in my code.

Thanks

Sunnybrad
0
 

Author Comment

by:sunnybrad
ID: 34199497
Hi:

How do you extract group one and group two the above regular expression breaks as well at run-time.

Best regards

Sunnybrad
0
 

Author Comment

by:sunnybrad
ID: 34199571
Hi:

I have solved this by saying if you don't match (.*):(.*).

Then the ssid part is null.

Thanks

Sunnybrad
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Need WiFi? Often, there are perfectly good networks that don't have WiFi capability - and there's a need to add it.  - Perhaps you have an Ethernet port into a network but no WiFi nearby. - Perhaps you have a powerline extender and no WiFi at the…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question