Solved

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

Posted on 2010-11-23
4
938 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
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JAVA API design with micro service cloud in mind 1 42
jmss example java 2 23
How to Link NetGear wireless AC-1200 router to Sonicwall 3600 13 59
hashmap order 17 36
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Using in-flight Wi-Fi when you travel? Business travelers beware! In-flight Wi-Fi networks could rip the door right off your digital privacy portal. That’s no joke either, as it might also provide a convenient entrance for bad threat actors.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to implement Singleton Design Pattern in Java.

809 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