Solved

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

Posted on 2010-11-23
4
923 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
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi:

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

Then the ssid part is null.

Thanks

Sunnybrad
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now