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 replaceHtmlTag(String str, String beforeTag, String tagAttrib, String startTag,
        String endTag) {//from   w  ww. ja  va 2  s. co m
    String regxpForTag = "<\\s*" + beforeTag + "\\s+([^>]*)\\s*>";
    String regxpForTagAttrib = tagAttrib + "=\"([^\"]+)\"";
    Pattern patternForTag = Pattern.compile(regxpForTag);
    Pattern patternForAttrib = Pattern.compile(regxpForTagAttrib);
    Matcher matcherForTag = patternForTag.matcher(str);
    StringBuffer sb = new StringBuffer();
    boolean result = matcherForTag.find();
    while (result) {
        StringBuffer sbreplace = new StringBuffer();
        Matcher matcherForAttrib = patternForAttrib.matcher(matcherForTag.group(1));
        if (matcherForAttrib.find()) {
            matcherForAttrib.appendReplacement(sbreplace, startTag + matcherForAttrib.group(1) + endTag);
        }
        matcherForTag.appendReplacement(sb, sbreplace.toString());
        result = matcherForTag.find();
    }
    matcherForTag.appendTail(sb);
    return sb.toString();
}

From source file:cop.raml.utils.javadoc.tags.TagLink.java

private static String getLinkClassName(String doc) {
    if (StringUtils.isBlank(doc))
        return null;

    Matcher matcher = PATTERN.matcher(doc);
    return matcher.find() ? matcher.group("cls") : null;
}

From source file:cop.raml.utils.javadoc.tags.TagLink.java

private static String getLinkParamName(String doc) {
    if (StringUtils.isBlank(doc))
        return null;

    Matcher matcher = PATTERN.matcher(doc);
    return matcher.find() ? matcher.group("par") : null;
}

From source file:net.alegen.datpass.cli.input.Command.java

private static List<String> split(String input) {
    List<String> matchList = new ArrayList<String>();
    Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
    Matcher regexMatcher = regex.matcher(input);
    while (regexMatcher.find()) {
        if (regexMatcher.group(1) != null)
            matchList.add(regexMatcher.group(1)); // Add double-quoted string without the quotes
        else if (regexMatcher.group(2) != null)
            matchList.add(regexMatcher.group(2)); // Add single-quoted string without the quotes
        else//from   w ww.jav  a2  s . co  m
            matchList.add(regexMatcher.group()); // Add unquoted word
    }
    return matchList;
}

From source file:io.cloudslang.lang.cli.SlangBootstrap.java

private static Set<String> findPropertyReferences(String value) {
    Matcher mather = SUBSTITUTION_PATTERN.matcher(value);
    Set<String> variableNames = new HashSet<>();
    while (mather.find()) {
        variableNames.add(mather.group(1));
    }/*from ww  w.j  av a2 s. com*/
    return variableNames;
}

From source file:nya.miku.wishmaster.http.recaptcha.RecaptchaNoscript.java

static String getChallenge(String publicKey, CancellableTask task, HttpClient httpClient, String scheme)
        throws Exception {
    if (scheme == null)
        scheme = "http";
    String response = HttpStreamer.getInstance().getStringFromUrl(scheme + RECAPTCHA_CHALLENGE_URL + publicKey,
            HttpRequestModel.builder().setGET().build(), httpClient, null, task, false);
    Matcher matcher = CHALLENGE_FIRST_PATTERN.matcher(response);
    if (matcher.find()) {
        String challenge = matcher.group(1);
        try {/*from w  w  w.j a v  a 2s . co  m*/
            response = HttpStreamer.getInstance().getStringFromUrl(
                    scheme + RECAPTCHA_RELOAD_URL + challenge + "&k=" + publicKey,
                    HttpRequestModel.builder().setGET().build(), httpClient, null, task, false);
            matcher = CHALLENGE_RELOAD_PATTERN.matcher(response);
            if (matcher.find()) {
                String newChallenge = matcher.group(1);
                if (newChallenge != null && newChallenge.length() > 0)
                    return newChallenge;
            }
        } catch (Exception e) {
            Logger.e(TAG, e);
        }

        return challenge;
    }
    throw new RecaptchaException("can't parse recaptcha challenge answer");
}

From source file:Main.java

public static String escape(String message) {
    if (message == null)
        return message;
    Matcher matcher = escapePattern.matcher(message);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        String replacement;//from w w w. j av  a  2  s .  c  o m
        if ("\"".equals(matcher.group()))
            replacement = "&quot;";
        else if ("&".equals(matcher.group()))
            replacement = "&amp;";
        else if ("'".equals(matcher.group()))
            replacement = "&apos;";
        else if ("<".equals(matcher.group()))
            replacement = "&lt;";
        else if (">".equals(matcher.group()))
            replacement = "&gt;";
        else
            throw new IllegalArgumentException();
        matcher.appendReplacement(sb, replacement);
    }
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:co.cask.cdap.client.rest.TestUtils.java

public static String getStreamNameFromUri(String uri) {
    String streamName = StringUtils.EMPTY;
    if (StringUtils.isNotEmpty(uri)) {
        Pattern p = Pattern.compile("streams/.*?/");
        Matcher m = p.matcher(uri);
        if (m.find()) {
            String b = m.group();
            streamName = b.substring(b.indexOf("/") + 1, b.length() - 1);
        }//from   w ww  .  j  a v  a2s.c om
    }
    return streamName;
}

From source file:at.gv.egovernment.moa.id.protocols.oauth20.OAuth20Util.java

public static boolean isValidStateValue(String state) {
    Pattern urlPattern = Pattern.compile("javascript|<|>|&|;", Pattern.CASE_INSENSITIVE);
    Matcher matcher = urlPattern.matcher(state);
    return !matcher.find();
}

From source file:com.nhncorp.lucy.security.xss.XssPreventer.java

/**
 * ?  XssPreventer  ?  ? ? . <br/>   
 * /*from  ww  w.j  av a 2  s.co  m*/
 * @param clean
 *            XssPreventer   ?.            
 * @return XssPreventer  ? ?.
 */
public static String unescape(String clean) {

    String str = StringEscapeUtils.unescapeHtml4(clean);

    if (str == null) {
        return null;
    }

    Matcher matcher = unescapePttern.matcher(str);

    if (matcher.find()) {
        return matcher.replaceAll("'");
    }

    return str;
}