I have a problem with these regular expressions. Based on the following code and knowing that the content of wemcamDetails is:
USB\VID_04F2&PID_B2E1&MI_00&9F9657C&0&1200 : Lenovo EasyCamera
Code:
String line = "";
if ((line = reader.readLine())!= null) {
if (line.startsWith("USB")){
webcamDetails = line;
}
}
String regEx1 = "^\S*";
String regEx2 = "\:(.*)";
String[] webcamID = webcamDetails.split(regEx1);
System.out.println("Device ID: "+webcamID[0]);
String[] webcamDeviceName = webcamDetails.split(regEx2);
System.out.println("Device Name: "+webcamDeviceName[0]);
I want to save USB\VID_04F2&PID_B2E1&MI_00&9F9657C&0&1200
in the variable webcamID, and Lenovo EasyCamera
in webcamDeviceName
. I have tested the regular expressions in several regex testers and they work, but for some reason that I do not know is not keeping me well in the variables, it always saves the first part of the String, but never saves the name of the camera. Can someone who controls me tell me what I'm doing wrong?