Java String Sub String subString(String original, String regex)

Here you can find the source of subString(String original, String regex)

Description

sub String

License

Open Source License

Declaration

public static String subString(String original, String regex) 

Method Source Code

//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 "";
    }
}

Related

  1. substring(String input, int maxLength)
  2. substring(String input, int maxLength)
  3. subString(String input, String startStr, String endStr)
  4. subString(String name)
  5. substring(String origin, int len)
  6. subString(String parentStr, String startStr, String endStr)
  7. substring(String S, int beginIndex, int endIndex)
  8. substring(String s, int beginIndex, int endIndex)
  9. substring(String s, int i, String substring, int direction)