Solved

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

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

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Question has a verified solution.

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

Multi-source agreements are important because they set standards that all manufacturers should follow to ensure that devices are compatible with multiple vendors. The multi-source agreement (MSA) is an agreement that establishes how multiple vendors…
For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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…

943 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

10 Experts available now in Live!

Get 1:1 Help Now