Example usage for java.util.regex Matcher find

List of usage examples for java.util.regex Matcher find

Introduction

In this page you can find the example usage for java.util.regex Matcher find.

Prototype

public boolean find() 

Source Link

Document

Attempts to find the next subsequence of the input sequence that matches the pattern.

Usage

From source file:Main.java

public static String getWithinTags(String matchString, String tag) {

    final Pattern pattern = Pattern.compile("<" + tag + ">(.+?)</" + tag + ">");
    final Matcher matcher = pattern.matcher(matchString);
    try {//from  w w  w.  java2 s.co  m
        matcher.find();
        return matcher.group(1);
    } catch (Exception e) {
        System.out.println("An exception has occured within tags: " + e.toString());
        return "";
    }
}

From source file:Main.java

public static String getToken(String source) {
    String tokenString = "";
    try {/*  w w  w. j a va 2s .c om*/
        String contentString = source;
        String regex = "token=(\\d*)";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(contentString);
        while (matcher.find()) {
            String getToken = matcher.group(1);
            if (getToken != null) {
                tokenString = getToken;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return tokenString;
}

From source file:Main.java

public static String makeCanonical(String classname) {
    Matcher matcher = PLAIN_NAME_START_PATTERN.matcher(classname);
    if (matcher.find()) {
        return classname.substring(0, matcher.start() + 1)
                + classname.substring(matcher.start() + 1, classname.length()).replace('.', '$');
    } else {/*from  w w  w .j a v a  2  s. co  m*/
        throw new IllegalArgumentException("Unable to identify the canonical name of " + classname);
    }
}

From source file:Main.java

public static final String getNameFromSelfLink(String selfLink) {
    Pattern p = Pattern.compile("([^/]+$)");
    Matcher m = p.matcher(selfLink);
    String name = null;/*from   w w w.j a  v  a2s .c om*/
    if (m.find()) {
        name = m.group(1);
    }
    return name;
}

From source file:Main.java

public static String delPreLocation(String regex, String content) {
    Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content);
    if (matcher.find()) {
        return content.substring(matcher.end(), content.length());
    }//from   www.j a  v a  2s .  c o  m
    return content;
}

From source file:Main.java

public static boolean isFindHttpsAtPrefixs(String _url) {
    Pattern pattern = Pattern.compile("^https://", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(_url.toLowerCase());
    return matcher.find();
}

From source file:Main.java

public static boolean isFindHttpAtPrefixs(String _url) {
    Pattern pattern = Pattern.compile("^http://", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(_url.toLowerCase());
    return matcher.find();
}

From source file:Main.java

@NonNull
public static List<String> getSplitString(String stringToSplit, int stringSplitLength) {
    /*//from  ww w.  j a  v  a 2 s . c o m
       length to split string needs to be at least as long as the longest series of non-whitespace in the string.
       E.G. if the following is the longest series of non-whitespace in the string
      "licences:"
       then stringSplitLength needs to be at least 9 (8 letters plus a colon)
     */
    stringSplitLength = Math.max(getLengthOfLongestWord(stringToSplit), stringSplitLength);

    List<String> splitString = new ArrayList<>();

    Pattern p = Pattern.compile("\\G\\s*(.{1," + stringSplitLength + "})(?=\\s|$)", Pattern.DOTALL);
    Matcher m2 = p.matcher(stringToSplit);
    while (m2.find()) {
        splitString.add(m2.group(1));
    }
    return splitString;
}

From source file:Main.java

public static CharSequence replace(Context ctx, String text) {
    SpannableString spannableString = new SpannableString(text);
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        String factText = matcher.group();
        String key = factText.substring(1);
        if (emotionTexts.contains(factText)) {
            Bitmap bitmap = getDrawableByName(ctx, key);
            ImageSpan image = new ImageSpan(ctx, bitmap);
            int start = matcher.start();
            int end = matcher.end();
            spannableString.setSpan(image, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }/*from  ww  w.  j a  v a  2  s.c o m*/
    }
    return spannableString;
}

From source file:Main.java

public static List<String> findAllMatches(String regularExpression, String contentsString) {
    List<String> allMatches = new ArrayList<String>();
    Matcher m = Pattern.compile(regularExpression).matcher(contentsString);
    while (m.find()) {
        allMatches.add(m.group());//from w ww  .j av  a 2s  .com
    }
    return allMatches;
}