當前位置: 首頁>>代碼示例>>Java>>正文


Java Matcher.find方法代碼示例

本文整理匯總了Java中java.util.regex.Matcher.find方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.find方法的具體用法?Java Matcher.find怎麽用?Java Matcher.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.regex.Matcher的用法示例。


在下文中一共展示了Matcher.find方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: camel2Underline

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static String camel2Underline(String fieldName) {
    if(fieldName == null||"".equals(fieldName)){
        return "";
    }
    fieldName = String.valueOf(fieldName.charAt(0)).toUpperCase().concat(fieldName.substring(1));
    StringBuffer sb=new StringBuffer();
    Pattern pattern=Pattern.compile("[A-Z]([a-z\\d]+)?");
    Matcher matcher=pattern.matcher(fieldName);
    while(matcher.find()){
        String word=matcher.group();
        sb.append(word.toUpperCase());
        sb.append(matcher.end() == fieldName.length() ? "" : "_");
    }
    return sb.toString();
}
 
開發者ID:myliang,項目名稱:fish-admin,代碼行數:16,代碼來源:SqlQuery.java

示例2: getContentNext

import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public String getContentNext(String baseUrl, String currentUrl, byte[] result) throws UnsupportedEncodingException {
    Document document = Jsoup.parse(new String(result, "gb2312"));
    Elements elements = document.select("div.pagelist a:contains(下一頁)");
    if (elements.size() > 0) {
        Pattern pattern = Pattern.compile("http.*/");
        Matcher matcher = pattern.matcher(currentUrl);
        if (matcher.find()) {
            return matcher.group() + elements.get(0).attr("href");
        }
    }
    return "";
}
 
開發者ID:lanyuanxiaoyao,項目名稱:PicKing,代碼行數:14,代碼來源:Nanrentu.java

示例3: addSmiles

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * replace existing spannable with smiles
 * @param context
 * @param spannable
 * @return
 */
public static boolean addSmiles(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Entry<Pattern, Object> 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;
                    break;
                }
            if (set) {
                hasChanges = true;
                Object value = entry.getValue();
                if(value instanceof String && !((String) value).startsWith("http")){
                    File file = new File((String) value);
                    if(!file.exists() || file.isDirectory()){
                        return false;
                    }
                    spannable.setSpan(new ImageSpan(context, Uri.fromFile(file)),
                            matcher.start(), matcher.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }else{
                    spannable.setSpan(new ImageSpan(context, (Integer)value),
                            matcher.start(), matcher.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
    }
    
    return hasChanges;
}
 
開發者ID:Vicent9920,項目名稱:FanChat,代碼行數:44,代碼來源:EaseSmileUtils.java

示例4: getScalePrecision

import java.util.regex.Matcher; //導入方法依賴的package包/類
private String getScalePrecision(String typeWithScale, int index) {

        String pattern = "decimal\\((\\d+),(\\d+)\\)";
        Pattern r = Pattern.compile(pattern);

        Matcher m = r.matcher(typeWithScale);
        if (m.find()) {
            return m.group(index);
        } else {
            return "-999";
        }
    }
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:13,代碼來源:HiveMetadataStrategy.java

示例5: pregMatch

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static String pregMatch(String content, String pattern, int index) {

        String match = "";
        Matcher matcher = Pattern.compile(pattern).matcher(content);

        while (matcher.find()) {
            match = matcher.group(index);
            break;
        }

        return TextCrawler.extendedTrim(match);
    }
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:13,代碼來源:Regex.java

示例6: whenWithInferredParams

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Convenience fluent builder for constructing a prime with a query, where the parameters are
 * inferred by the query
 *
 * @param query The query string to match against.
 * @return builder for this prime.
 */
private static PrimeBuilder whenWithInferredParams(String query) {
  long posParamCount = query.chars().filter(num -> num == '?').count();

  // Do basic param population for positional types
  HashMap<String, String> paramTypes = new HashMap<>();
  HashMap<String, Object> params = new HashMap<>();
  if (posParamCount > 0) {
    for (int i = 0; i < posParamCount; i++) {
      params.put(Integer.toString(i), "*");
      paramTypes.put(Integer.toString(i), "varchar");
    }
  }
  // Do basic param population for named types
  else {
    List<String> allMatches = new ArrayList<>();
    Pattern p = Pattern.compile("([\\w']+)\\s=\\s:[\\w]+");
    Matcher m = p.matcher(query);
    while (m.find()) {
      allMatches.add(m.group(1));
    }
    for (String match : allMatches) {
      params.put(match, "*");
      paramTypes.put(match, "varchar");
    }
  }
  return when(
      new com.datastax.oss.simulacron.common.request.Query(
          query, Collections.emptyList(), params, paramTypes));
}
 
開發者ID:datastax,項目名稱:simulacron,代碼行數:37,代碼來源:BoundNode.java

示例7: parseIP

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * @return IP Address as a string
 */
public static String parseIP(InetSocketAddress add) {
    Matcher matcher = IP_PATTERN.matcher(add.toString());
    if (matcher.find()) {
        return matcher.group();
    }
    return "";
}
 
開發者ID:edasaki,項目名稱:ZentrelaCore,代碼行數:11,代碼來源:PunishmentManager.java

示例8: parse

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static String parse(List<List<ChartCharacter>> lines) {
    boolean footnotesFound = false;
    List<ChartCharacter> footnotes = new ArrayList<>();
    for (List<ChartCharacter> line : lines) {
        String text = Chart.convertToText(line);

        Matcher matcher = COPYRIGHT_PATTERN.matcher(text);
        if (matcher.find()) {
            footnotesFound = false;
        }

        matcher = HANDLE.matcher(text);
        if (matcher.find()) {
            footnotesFound = false;
        }

        if (footnotesFound) {
            footnotes.addAll(line);
        }

        matcher = FOOTNOTES.matcher(text);
        if (matcher.find()) {
            footnotesFound = true;
        }
    }

    String notes = Chart.convertToText(footnotes);
    notes = notes.replaceAll("\nDenotes a Keeneland Sales Graduate", "")
            .replaceAll("\n", " ")
            .replaceAll("\\|", " ");

    return notes;
}
 
開發者ID:robinhowlett,項目名稱:chart-parser,代碼行數:34,代碼來源:Footnotes.java

示例9: lexVerbatimData

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Implementation of the "verbatim" tag
 *
 * @throws ParserException
 */
private void lexVerbatimData(Matcher verbatimStartMatcher) throws ParserException {

    // move cursor past the opening verbatim tag
    source.advance(verbatimStartMatcher.end());

    // look for the "endverbatim" tag and storing everything between
    // now and then into a TEXT node
    Matcher verbatimEndMatcher = this.syntax.getRegexVerbatimEnd().matcher(source);

    // check for EOF
    if (!verbatimEndMatcher.find()) {
        throw new ParserException(null, "Unclosed verbatim tag.", source.getLineNumber(), source.getFilename());
    }
    String verbatimText = source.substring(verbatimEndMatcher.start());

    // check if the verbatim start tag has a trailing whitespace trim
    if (verbatimStartMatcher.group(0) != null) {
        verbatimText = StringUtils.ltrim(verbatimText);
    }

    // check if the verbatim end tag had a leading whitespace trim
    if (verbatimEndMatcher.group(1) != null) {
        verbatimText = StringUtils.rtrim(verbatimText);
    }

    // check if the verbatim end tag had a trailing whitespace trim
    if (verbatimEndMatcher.group(2) != null) {
        trimLeadingWhitespaceFromNextData = true;
    }

    // move cursor past the verbatim text and end delimiter
    source.advance(verbatimEndMatcher.end());

    pushToken(Type.TEXT, verbatimText);
}
 
開發者ID:flapdoodle-oss,項目名稱:de.flapdoodle.solid,代碼行數:41,代碼來源:LexerImpl.java

示例10: stdoutShouldMatch

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Verify that the stdout contents of output buffer matches the
 * pattern
 *
 * @param pattern
 * @throws RuntimeException If the pattern was not found
 */
public void stdoutShouldMatch(String pattern) {
    Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
    if (!matcher.find()) {
        throw new RuntimeException("'" + pattern
                + "' missing from stdout: [" + stdout + "]\n");
    }
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:15,代碼來源:OutputAnalyzer.java

示例11: underlineToCamelhump

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * 將下劃線風格替換為駝峰風格
 */
public static String underlineToCamelhump(String str) {
    Matcher matcher = Pattern.compile("_[a-z]").matcher(str);
    StringBuilder builder = new StringBuilder(str);
    for (int i = 0; matcher.find(); i++) {
        builder.replace(matcher.start() - i, matcher.end() - i, matcher.group().substring(1).toUpperCase());
    }
    if (Character.isUpperCase(builder.charAt(0))) {
        builder.replace(0, 1, String.valueOf(Character.toLowerCase(builder.charAt(0))));
    }
    return builder.toString();
}
 
開發者ID:godlike110,項目名稱:tk-mybatis,代碼行數:15,代碼來源:StringUtil.java

示例12: testMultiRequestHeaders

import java.util.regex.Matcher; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
@OnlyRunNativeCronet
public void testMultiRequestHeaders() throws Exception {
    TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCallback();
    String headerName = "header-name";
    String headerValue1 = "header-value1";
    String headerValue2 = "header-value2";
    BidirectionalStream.Builder builder =
            new BidirectionalStream.Builder(Http2TestServer.getEchoAllHeadersUrl(), callback,
                    callback.getExecutor(), mTestFramework.mCronetEngine);
    builder.addHeader(headerName, headerValue1);
    builder.addHeader(headerName, headerValue2);
    builder.setHttpMethod("GET");
    builder.build().start();
    callback.blockForDone();
    assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
    String headers = callback.mResponseAsString;
    Pattern pattern = Pattern.compile(headerName + ":\\s(.*)\\r\\n");
    Matcher matcher = pattern.matcher(headers);
    List<String> actualValues = new ArrayList<String>();
    while (matcher.find()) {
        actualValues.add(matcher.group(1));
    }
    assertEquals(1, actualValues.size());
    assertEquals("header-value2", actualValues.get(0));
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:28,代碼來源:BidirectionalStreamTest.java

示例13: parseAudios

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static AbsLink parseAudios(String string) {
    Matcher matcher = PATTERN_AUDIOS.matcher(string);
    if (!matcher.find()) {
        return null;
    }

    return new AudiosLink(parseInt(matcher.group(1)));
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:9,代碼來源:VkLinkParser.java

示例14: findResource

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static int findResource(String val, String units)
  throws AllocationConfigurationException {
  Pattern pattern = Pattern.compile("(\\d+)\\s*" + units);
  Matcher matcher = pattern.matcher(val);
  if (!matcher.find() && !units.equals("gcores")) {
    throw new AllocationConfigurationException("Missing resource: " + units);
  } else {
    return matcher.find(0) ? Integer.parseInt(matcher.group(1)) : 0;
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:11,代碼來源:FairSchedulerConfiguration.java

示例15: parseRaceDistance

import java.util.regex.Matcher; //導入方法依賴的package包/類
static RaceDistance parseRaceDistance(String distanceDescription) throws ChartParserException {
    String lcDistanceDescription = distanceDescription.toLowerCase();
    Matcher milesOnlyMatcher = MILES_ONLY_PATTERN.matcher(lcDistanceDescription);
    if (milesOnlyMatcher.find()) {
        return forMiles(distanceDescription, milesOnlyMatcher);
    }
    Matcher furlongsOnlyMatcher = FURLONGS_ONLY_PATTERN.matcher(lcDistanceDescription);
    if (furlongsOnlyMatcher.find()) {
        return forFurlongs(distanceDescription, furlongsOnlyMatcher);
    }
    Matcher yardsOnlyMatcher = YARDS_ONLY_PATTERN.matcher(lcDistanceDescription);
    if (yardsOnlyMatcher.find()) {
        return forYards(distanceDescription, yardsOnlyMatcher);
    }
    Matcher milesAndYardsMatcher = MILES_YARDS_PATTERN.matcher(lcDistanceDescription);
    if (milesAndYardsMatcher.find()) {
        return forMilesAndYards(distanceDescription, milesAndYardsMatcher);
    }
    Matcher furlongsAndYardsMatcher = FURLONGS_YARDS_PATTERN.matcher(lcDistanceDescription);
    if (furlongsAndYardsMatcher.find()) {
        return forFurlongsAndYards(distanceDescription, furlongsAndYardsMatcher);
    }
    // sometimes the "Yards" part is missing
    Matcher missingYardsMatcher = MISSING_YARDS_PATTERN.matcher(lcDistanceDescription);
    if (missingYardsMatcher.find()) {
        return forYards(distanceDescription, missingYardsMatcher);
    }

    throw new ChartParserException(String.format("Unable to parse race distance from text: " +
            "%s", distanceDescription));
}
 
開發者ID:robinhowlett,項目名稱:chart-parser,代碼行數:32,代碼來源:DistanceSurfaceTrackRecord.java


注:本文中的java.util.regex.Matcher.find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。