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:com.company.vertxstarter.api.util.SortExpression.java

public static SortExpression parse(String str) {
    Matcher m = PATTERN.matcher(str);
    if (!m.find()) {
        return null;
    }/*ww w  .java 2  s. c o  m*/

    SortExpression exp = new SortExpression();
    exp.setOrder(parseOrder(m.group(1)));
    if (exp.getOrder() == Order.NONE) {
        return null;
    }
    exp.setField(m.group(2));
    return exp;
}

From source file:Main.java

static String[] getPortValues(String val) {
    Matcher m = pRegEx.matcher(val);
    String[] ret = new String[5];
    if (m.find()) {
        ret[0] = m.group(1);//w w w . ja  v  a2  s  .  co  m
        ret[1] = m.group(2);
        ret[2] = m.group(3);
        ret[3] = m.group(4);
        ret[4] = m.group(5);

    }
    return ret;
}

From source file:Main.java

public static boolean addEmoticons(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Entry<Pattern, Integer> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(spannable);
        while (matcher.find()) {
            boolean set = true;
            for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class))
                if (spannable.getSpanStart(span) >= matcher.start()
                        && spannable.getSpanEnd(span) <= matcher.end())
                    spannable.removeSpan(span);
                else {
                    set = false;//w  w w.  j  a  va  2 s . c om
                    break;
                }
            if (set) {
                hasChanges = true;
                spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return hasChanges;
}

From source file:Main.java

private static String lowerCaseAttributes(String formatted) {
    Matcher m = ID_PATTERN.matcher(formatted);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String text = m.group();/*w w  w  .  ja  va 2  s  .  com*/
        m.appendReplacement(sb, Matcher.quoteReplacement(text.toLowerCase()));
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.krminc.phr.api.converter.util.ConverterUtils.java

public static final Boolean isValidPhoneNumber(String phonenumber) {
    phonenumber = prepareInput(phonenumber);
    //number is optional 1 followed by 3 4 4 digits with optional non-digits surrounding
    final String CONTACT_REGEX = "^1?\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$";
    Pattern pattern = Pattern.compile(CONTACT_REGEX);
    Matcher matcher = pattern.matcher(phonenumber);
    if (matcher.find()) {
        return true;
    }/*from  www.  j  a  v  a  2  s.c om*/
    return false;
}

From source file:com.onehippo.gogreen.utils.UserAgentUtils.java

public static boolean isMobile(HttpServletRequest request) {
    String userAgent = request.getHeader("User-Agent");
    if (StringUtils.isEmpty(userAgent)) {
        return false;
    }//from   w  ww.j  a v a 2s .c  o  m
    for (final Pattern pattern : mobileUserAgentPatterns) {
        final Matcher matcher = pattern.matcher(userAgent);
        if (matcher.find()) {
            return true;
        }
    }

    return false;
}

From source file:Main.java

static String parseContentDisposition(String contentDisposition) {
    try {/*from w w  w.  ja  v a  2  s  .  c  o m*/
        Matcher m = CONTENT_DISPOSITION_PATTERN.matcher(contentDisposition);
        if (m.find()) {
            return m.group(1);
        }
    } catch (IllegalStateException ex) {
        // This function is defined as returning null when it can't parse
        // the header
    }
    return null;
}

From source file:Main.java

/**
 * Extracts the objid from the provided resource XML representation.<br/> Either the first occurence of objid="..."
 * is searched and the value is returned, or the first occurence of :href="..." is searched and from this value the
 * objid is extracted and returned.//from   www.  j a  va 2  s  .c o  m
 *
 * @param resourceXml The XML representation of the resource to get the objid from.
 * @return Returns the extracted objid or {@code null}.
 */
public static String getIdFromXml(final CharSequence resourceXml) {

    final Matcher matcher = PATTERN_OBJID_FROM_XML.matcher(resourceXml);
    return matcher.find() ? matcher.group(2) : null;
}

From source file:Main.java

private static String parseContentDisposition(String contentDisposition) {
    try {/*from w w  w  .ja va2s.c  om*/
        Matcher m = CONTENT_DISPOSITION_PATTERN.matcher(contentDisposition);
        if (m.find()) {
            return m.group(1);
        }
    } catch (IllegalStateException ex) {
        // This function is defined as returning null when it can't parse
        // the header
    }
    return null;
}

From source file:Main.java

public static boolean addSmiles(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Map.Entry<Pattern, Integer> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(spannable);
        while (matcher.find()) {
            boolean set = true;
            for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class))
                if (spannable.getSpanStart(span) >= matcher.start()
                        && spannable.getSpanEnd(span) <= matcher.end())
                    spannable.removeSpan(span);
                else {
                    set = false;/*from  w  w  w. j  a  v a  2 s.  c  o  m*/
                    break;
                }
            if (set) {
                hasChanges = true;
                spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return hasChanges;
}