I want to cut the string using regexp, but not to cut the regexp part…
String path ="house/room/cabinet/my_books/bought/2011/adventure/Black-Ship01/312 pages/...";
String[] substract=path.split("my_");
path=substract1[1].toString();// books/bought/2011/adventure/Black-Ship01/312 pages/...
String[] substract2=path.split("-Ship.."); //split using -Ship and two random simbols
path=substract[1].toString();
RESULT: path= "books/bought/2011/adventure/Black"
Should be path= "books/bought/2011/adventure/Black-Ship01"
so how to add -Ship01 ??
Try using positive lookbehind:
String[] substract2=path.split("(?<=-Ship..)"). This matches the pattern but doesn’t consume the characters.