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


Java Matcher.start方法代碼示例

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


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

示例1: segment

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * 分詞
 * @param text 文本
 * @return 分詞結果
 */
public static List<Term> segment(String text)
{
    List<Term> termList = new LinkedList<Term>();
    Matcher matcher = WEB_URL.matcher(text);
    int begin = 0;
    int end;
    while (matcher.find())
    {
        end = matcher.start();
        termList.addAll(SEGMENT.seg(text.substring(begin, end)));
        termList.add(new Term(matcher.group(), Nature.xu));
        begin = matcher.end();
    }
    if (begin < text.length()) termList.addAll(SEGMENT.seg(text.substring(begin)));

    return termList;
}
 
開發者ID:priester,項目名稱:hanlpStudy,代碼行數:23,代碼來源:URLTokenizer.java

示例2: findTemplate

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Finds the template with the specified name.
 *
 * @param where where the template should be found.
 * @param templateName name of the template.
 * @return template information.
 */
private static TemplateInfo findTemplate(String where, String templateName) {
    String marker = markerRegexp(templateName, false);
    Pattern pattern = Pattern.compile(marker+"(.*?)"+marker, Pattern.DOTALL); // NOI18N
    Matcher matcher = pattern.matcher(where);
    matcher.find();
    TemplateInfo info = new TemplateInfo();
    int index1 = matcher.start(1);
    int index2 = matcher.end(1);
    info.template = where.substring(index1, index2);
    index1 = matcher.start();
    index2 = matcher.end();
    info.form = where.substring(0,index1) + where.substring(index2);
    info.formIndex = index1;
    return info;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:MasterDetailGenerator.java

示例3: getUrlsFromText

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * @param textContent
 * @return
 */
public static List<String> getUrlsFromText(String textContent)
{
    List<String> result = new ArrayList<String>();
    Pattern urlPattern = Pattern.compile("(?:^|[\\W])((http|ftp)(s?):\\/\\/|www\\.)" + "(([\\w\\-]+\\.){1,}?" +
            "([\\w\\-.~]+\\/?)*" + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*[email protected]!:/{};']*)", Pattern.CASE_INSENSITIVE |
            Pattern.MULTILINE | Pattern.DOTALL);
    Matcher m = urlPattern.matcher(textContent);
    while (m.find())
    {
        int matchStart = m.start(1);
        int matchEnd = m.end();
        result.add(textContent.substring(matchStart, matchEnd));
        LOG.info("url found : " + textContent.substring(matchStart, matchEnd));
    }
    return result;
}
 
開發者ID:basavaraj1985,項目名稱:DolphinNG,代碼行數:21,代碼來源:StringUtil.java

示例4: matchTopic

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static Spannable matchTopic(Spannable spannable) {
    String text = spannable.toString();

    Pattern pattern = Pattern.compile(MATCH_TOPIC);
    Matcher matcher = pattern.matcher(text);

    while (matcher.find()) {
        String str = matcher.group();
        int matcherStart = matcher.start();
        int matcherEnd = matcher.end();
        spannable.setSpan(new RichEditText.TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        log("matchTopic:" + str + " " + matcherStart + " " + matcherEnd);
    }

    return spannable;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:17,代碼來源:RichEditText.java

示例5: findMeta

import java.util.regex.Matcher; //導入方法依賴的package包/類
@VisibleForTesting
protected static Maybe<MetaAndContent> findMeta(Pattern startMarker, Pattern endMarker, String content) {
	Matcher startMatcher = startMarker.matcher(content);
	
	if (startMatcher.find()) {
		int startOfMeta = startMatcher.end();
		
		Matcher endMatcher = endMarker.matcher(content);
		if (endMatcher.find(startOfMeta)) {
			int endOfMeta=endMatcher.start();
			int startOfContent=endMatcher.end();
			return Maybe.of(MetaAndContent.of(content.substring(startOfMeta, endOfMeta), content.substring(startOfContent)));
		}
	}
	
	return Maybe.empty();
}
 
開發者ID:flapdoodle-oss,項目名稱:de.flapdoodle.solid,代碼行數:18,代碼來源:DefaultBlobParser.java

示例6: translateLastToTab

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static String translateLastToTab(String target){
    Pattern pattern = Pattern.compile("\\[([^\\[\\]]+)\\]");
    Matcher matcher = pattern.matcher(target);

    StringBuilder sb = new StringBuilder();

    int start = 0;
    int end;
    while (matcher.find()) {
        end = matcher.start(1);
        sb.append(target.substring(start, end));
        sb.append(replaceLast(matcher.group(1),"-", "\t"));
        start = matcher.end(1);
    }
    sb.append(target.substring(start, target.length()));

    return sb.toString();

}
 
開發者ID:nilshoffmann,項目名稱:jmzTab-m,代碼行數:20,代碼來源:MZTabUtils.java

示例7: check

import java.util.regex.Matcher; //導入方法依賴的package包/類
void check(String out, int count) {
    System.err.println(out);
    Pattern warn = Pattern.compile("warning - @param argument \"i[0-9]+\" is not a parameter name");
    Matcher m = warn.matcher(out);
    int n = 0;
    for (int start = 0; m.find(start); start = m.start() + 1) {
        n++;
    }
    if (n != count)
        error("unexpected number of warnings reported: " + n + "; expected: " + count);

    Pattern warnCount = Pattern.compile("(?ms).*^([0-9]+) warnings$.*");
    m = warnCount.matcher(out);
    if (m.matches()) {
        n = Integer.parseInt(m.group(1));
        if (n != count)
            error("unexpected number of warnings reported: " + n + "; expected: " + count);
    } else
        error("total count not found");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:MaxWarns.java

示例8: fileRange

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static UnderlinedRange fileRange(int line, int column, Matcher matcher) {
  int rangeLine = line;
  int rangeColumn = column + matcher.start("range");
  int rangeEndLine = line;
  int rangeEndColumn = column + matcher.end("range") - 1;
  String params = matcher.group("params");
  if (params != null) {
    rangeEndColumn = rangeColumn;
    Map<String, String> paramMap = NoncompliantCommentParser.extractParams(params);
    rangeLine = consumePropertyAndAdjustValue(rangeLine, paramMap, "sl");
    rangeColumn = consumePropertyAndAdjustValue(rangeColumn, paramMap, "sc");
    rangeEndColumn = consumePropertyAndAdjustValue(rangeEndColumn, paramMap, "ec");
    rangeEndLine = consumePropertyAndAdjustValue(rangeEndLine, paramMap, "el");
    if (!paramMap.isEmpty()) {
      throw new IllegalStateException("Unknown attributes at line " + line + " in: " + params);
    }
  }
  return new UnderlinedRange(rangeLine, rangeColumn, rangeEndLine, rangeEndColumn);
}
 
開發者ID:SonarSource,項目名稱:sonar-analyzer-commons,代碼行數:20,代碼來源:PreciseLocationParser.java

示例9: searchAllText

import java.util.regex.Matcher; //導入方法依賴的package包/類
public int searchAllText(String textToSearch, BasicTextSearchCriteria searchCriteria) {
    matchedResults.clear();

    if (textToSearch == null) {
        return 0;
    }

    Pattern pattern = searchCriteria.getRegularExpressionPattern();
    if (pattern == null)   //this happens if the user clears the 'search for' text. We have no pattern.
    {
        return 0;
    }

    Matcher matcher = pattern.matcher(textToSearch);

    searchCriteria.resetHasChanged();

    boolean wasMatchFound = false;
    int matcherStart = 0;

    do {
        wasMatchFound = matcher.find(matcherStart);   //this will reset our search so we'll start at our new location
        if (wasMatchFound) {
            // Retrieve matching string
            String matchedText = matcher.group();

            // Retrieve indices of matching string
            int start = matcher.start();
            int end = matcher.end();

            matchedResults.add(new SearchResult(matchedText, start, end));

            matcherStart = end + 1;
        }
    }
    while (wasMatchFound);

    return matchedResults.size();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:40,代碼來源:TextBlockSearchEditor.java

示例10: replaceInnerSpaces

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static void replaceInnerSpaces(String[] strings, int idx) {
    Matcher m = spaces.matcher(strings[idx]);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        if (m.start() == 0 || m.end() == strings[idx].length()) {
            m.appendReplacement(sb, "$1");
        } else {
            m.appendReplacement(sb, "");
        }
    }
    m.appendTail(sb);
    strings[idx] = sb.toString();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:HuntDiff.java

示例11: Highlighter

import java.util.regex.Matcher; //導入方法依賴的package包/類
public Highlighter( String text ) {
	
	String stripped = STRIPPER.matcher( text ).replaceAll( "" );
	mask = new boolean[stripped.length()];
	
	Matcher m = HIGHLIGHTER.matcher( stripped );
	
	int pos = 0;
	int lastMatch = 0;
	
	while (m.find()) {
		pos += (m.start() - lastMatch);
		int groupLen = m.group( 1 ).length();
		for (int i=pos; i < pos + groupLen; i++) {
			mask[i] = true;
		}
		pos += groupLen;
		lastMatch = m.end();
	}
	
	m.reset( text );
	StringBuffer sb = new StringBuffer();
	while (m.find()) {
		m.appendReplacement( sb, m.group( 1 ) );
	}
	m.appendTail( sb );
	
	this.text = sb.toString();
}
 
開發者ID:kurtyu,項目名稱:PixelDungeonTC,代碼行數:30,代碼來源:Highlighter.java

示例12: regExIndex

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static int regExIndex(String text, Integer fromIndex){
    Matcher matcher = compiledPattern.matcher(text);
    if ( ( fromIndex != null && matcher.find(fromIndex) ) || matcher.find()) {
        return matcher.start();
    }
    return -1;
}
 
開發者ID:sweetca,項目名稱:logger,代碼行數:8,代碼來源:LogUtil.java

示例13: completionSuggestionsImpl

import java.util.regex.Matcher; //導入方法依賴的package包/類
private List<Suggestion> completionSuggestionsImpl(String code, int cursor, int[] anchor) {
    code = code.substring(0, cursor);
    Matcher m = JAVA_IDENTIFIER.matcher(code);
    String identifier = "";
    while (m.find()) {
        if (m.end() == code.length()) {
            cursor = m.start();
            code = code.substring(0, cursor);
            identifier = m.group();
        }
    }
    code = code.substring(0, cursor);
    if (code.trim().isEmpty()) { //TODO: comment handling
        code += ";";
    }
    OuterWrap codeWrap;
    switch (guessKind(code)) {
        case IMPORT:
            codeWrap = proc.outerMap.wrapImport(Wrap.simpleWrap(code + "any.any"), null);
            break;
        case CLASS:
        case METHOD:
            codeWrap = proc.outerMap.wrapInTrialClass(Wrap.classMemberWrap(code));
            break;
        default:
            codeWrap = proc.outerMap.wrapInTrialClass(Wrap.methodWrap(code));
            break;
    }
    String requiredPrefix = identifier;
    return computeSuggestions(codeWrap, cursor, anchor).stream()
            .filter(s -> s.continuation().startsWith(requiredPrefix) && !s.continuation().equals(REPL_DOESNOTMATTER_CLASS_NAME))
            .sorted(Comparator.comparing(Suggestion::continuation))
            .collect(collectingAndThen(toList(), Collections::unmodifiableList));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:SourceCodeAnalysisImpl.java

示例14: parse

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Convert a SQL LIKE operator Value to a Regular Expression.
 */
public HBaseRegexParser parse() {
  if (regexString_ != null) {
    return this;
  }

  Matcher matcher = null;
  StringBuilder prefixSB = new StringBuilder();
  StringBuilder regexSB = new StringBuilder("^"); // starts with
  if (escapeChar_ == null) {
    matcher = SQL_LIKE_REGEX.matcher(likeString_);
  } else {
    /*
     * When an escape character is specified, add another capturing group
     * with the escape character in the front for the escape sequence and
     * add the escape character to the exclusion list of literals
     */
    matcher = Pattern.compile(
        String.format(SQL_LIKE_ESCAPE_REGEX_STR, escapeChar_, escapeChar_))
      .matcher(likeString_);
  }
  String fragment = null;
  boolean literalsSoFar = true;
  while (matcher.find()) {
    if (escapeChar_ != null && matcher.group(1) != null) {
      fragment = matcher.group(1);
      if (fragment.length() != 2) {
        throw new IllegalArgumentException("Invalid fragment '"
            + fragment + "' at index " + matcher.start()
            + " in the LIKE operand '" + likeString_ + "'");
      }
      String escapedChar = fragment.substring(1);
      if (literalsSoFar) {
        prefixSB.append(escapedChar);
      }
      regexSB.append(Pattern.quote(escapedChar));
    } else {
      fragment = matcher.group();
      switch (fragment) {
      case "_": // LIKE('_') => REGEX('.')
        literalsSoFar = false;
        regexSB.append(".");
        break;
      case "%": // LIKE('%') => REGEX('.*')
        literalsSoFar = false;
        regexSB.append(".*");
        break;
      default: // ALL other including character ranges
        if (fragment.startsWith("[") && fragment.endsWith("]")) {
          literalsSoFar = false;
          regexSB.append(fragment);
        } else {
          if (literalsSoFar) {
            prefixSB.append(fragment);
          }
          // found literal, just quote it.
          regexSB.append(Pattern.quote(fragment));
        }
        break;
      }
    }
  }
  prefixString_ = prefixSB.toString();
  regexString_ = regexSB.append("$") // ends with
      .toString();

  logger.debug("Converted LIKE string '{}' to REGEX string '{}'.", likeString_, regexString_);
  return this;
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:72,代碼來源:HBaseRegexParser.java

示例15: parseRule

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static Map<String, MatchPair> parseRule(String rule)
        throws ParseException {
    Map<String, MatchPair> condition = new HashMap<String, MatchPair>();
    if(StringUtils.isBlank(rule)) {
        return condition;
    }        
    // 匹配或不匹配Key-Value對
    MatchPair pair = null;
    // 多個Value值
    Set<String> values = null;
    final Matcher matcher = ROUTE_PATTERN.matcher(rule);
    while (matcher.find()) { // 逐個匹配
        String separator = matcher.group(1);
        String content = matcher.group(2);
        // 表達式開始
        if (separator == null || separator.length() == 0) {
            pair = new MatchPair();
            condition.put(content, pair);
        }
        // KV開始
        else if ("&".equals(separator)) {
            if (condition.get(content) == null) {
                pair = new MatchPair();
                condition.put(content, pair);
            } else {
                condition.put(content, pair);
            }
        }
        // KV的Value部分開始
        else if ("=".equals(separator)) {
            if (pair == null)
                throw new ParseException("Illegal route rule \""
                        + rule + "\", The error char '" + separator
                        + "' at index " + matcher.start() + " before \""
                        + content + "\".", matcher.start());

            values = pair.matches;
            values.add(content);
        }
        // KV的Value部分開始
        else if ("!=".equals(separator)) {
            if (pair == null)
                throw new ParseException("Illegal route rule \""
                        + rule + "\", The error char '" + separator
                        + "' at index " + matcher.start() + " before \""
                        + content + "\".", matcher.start());

            values = pair.mismatches;
            values.add(content);
        }
        // KV的Value部分的多個條目
        else if (",".equals(separator)) { // 如果為逗號表示
            if (values == null || values.size() == 0)
                throw new ParseException("Illegal route rule \""
                        + rule + "\", The error char '" + separator
                        + "' at index " + matcher.start() + " before \""
                        + content + "\".", matcher.start());
            values.add(content);
        } else {
            throw new ParseException("Illegal route rule \"" + rule
                    + "\", The error char '" + separator + "' at index "
                    + matcher.start() + " before \"" + content + "\".", matcher.start());
        }
    }
    return condition;
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:67,代碼來源:ConditionRouter.java


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