fork download
  1. /* http://es.stackoverflow.com/q/48426/127 */
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. final String regex = "^(USB\\S*)\\s*:\\s*(.*)";
  11. final String string = "USB\\VID_04F2&PID_B2E1&MI_00\\6&9F9657C&0&1200 : Lenovo EasyCamera";
  12.  
  13. final Pattern pattern = Pattern.compile(regex);
  14. final Matcher matcher = pattern.matcher(string);
  15.  
  16. if (matcher.find()) {
  17. String webcamID = matcher.group(1);
  18. String webcamDeviceName = matcher.group(2);
  19.  
  20. System.out.println("Device ID: "+webcamID);
  21. System.out.println("Device Name: "+webcamDeviceName);
  22. }
  23. }
  24. }
Success #stdin #stdout 0.03s 711168KB
stdin
Standard input is empty
stdout
Device ID: USB\VID_04F2&PID_B2E1&MI_00\6&9F9657C&0&1200
Device Name: Lenovo EasyCamera