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,874
  • 5
  • 41
  • 58
boiledwater
  • 10,372
  • 4
  • 37
  • 38

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
  • 107,652
  • 25
  • 181
  • 264