0
public class Main {
    /**
     * @param args
     */
    public static void main(String[] args) {
        String url="http://a.b.com/m/test/index";
        System.out.println(url.replaceAll("^.*?((?<!/)(?:/)(?!/))", ""));
    }
}

The system print is: m/test/index. But in my mind it should print is:/m/test/index. Somebody give some reason?

Buddy
  • 10,627
  • 5
  • 40
  • 57
boiledwater
  • 10,234
  • 4
  • 35
  • 37

1 Answers1

2

Your regex reads "As few characters as possible up to and including the first slash that is neither preceded nor followed by a slash". The slash itself is clearly included in the regex. The fact that it is in a non-capturing group does not mean that it is not part of the match.

Mad Physicist
  • 95,415
  • 23
  • 151
  • 231