0

Do you know what is wrong here?

    Pattern pathsPatter = Pattern.compile("\"([^\"]+)\"");
    Matcher pathsMatcher = pathsPatter.matcher(commandAndParameters[1]);

I want to capture the group between " ". For example, if the string is

    mv "C:\Users\" "D:\"

the matcher should capture:

    C:\Users\
    D:\
4
  • What output do you get now? Commented Mar 17, 2013 at 11:15
  • Nothing. It doesn't capture anything. Commented Mar 17, 2013 at 11:15
  • 3
    it is already answered here stackoverflow.com/questions/171480/… Commented Mar 17, 2013 at 11:16
  • It works for me ideone.com/vsx1fQ Commented Mar 17, 2013 at 11:21

2 Answers 2

1

Try out this pattern :

    String data = "mv \"C:\\Users\\\" \"D:\\\"";

    Pattern pattern = Pattern.compile("\"(.+?)\"");
    Matcher matcher = pattern.matcher(data);
    System.out.println("Started");
    while (matcher.find()) {
        System.out.println(matcher.group(1));
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Works fine here:

Pattern pathsPattern = Pattern.compile("\"([^\"]+)\"");
Matcher pathsMatcher = pathsPattern.matcher("mv \"C:\\Users\\\" \"D:\\\"");
pathsMatcher.find();
System.out.println("found " + pathsMatcher.group(1)); // prints: found C:\Users\
pathsMatcher.find();
System.out.println("found " + pathsMatcher.group(1)); // prints: found D:\

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.