Here you can find the source of subString(String original, String regex)
public static String subString(String original, String regex)
//package com.java2s; //License from project: Open Source License public class Main { public static String subString(String or, String from, String to) { int i = or.indexOf(from); int j = or.indexOf(to, i); return or.substring(i, j); }// w ww.ja v a2s . c o m public static String subString(String original, String regex) { int end; boolean found = false; for (end = 1; end < original.length(); end++) { if (original.substring(0, end).matches(regex)) { found = true; } else if (found) return original.substring(0, end - 1); } if (original.substring(0, original.length() - 1).matches(regex)) return original.substring(0, original.length() - 1); if (original.substring(0, original.length()).matches(regex)) return original; return ""; } }