当前位置: 首页>>代码示例>>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;未经允许,请勿转载。