java.util.regex.Matcher.end()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中java.util.regex.Matcher.end()方法的一些代码示例,展示了Matcher.end()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.end()方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:end

Matcher.end介绍

[英]Returns the index of the first character following the text that matched the whole regular expression.
[中]返回与整个正则表达式匹配的文本后面的第一个字符的索引。

代码示例

代码示例来源:origin: jenkinsci/jenkins

public SubText(Matcher m, int textOffset) {
  start = m.start() + textOffset;
  end   = m.end() + textOffset;
  int cnt = m.groupCount();
  groups = new int[cnt*2];
  for( int i=0; i<cnt; i++ ) {
    groups[i*2  ] = m.start(i+1) + textOffset;
    groups[i*2+1] = m.end(i+1) + textOffset;
  }
}

代码示例来源:origin: jenkinsci/jenkins

String applyPatternRepeatedly(@Nonnull Pattern pattern, @Nonnull String filename,
               @Nonnull Function<String, Character> converter) {
  StringBuilder id = new StringBuilder();
  int beginIndex = 0;
  Matcher matcher = pattern.matcher(filename);
  while (matcher.find()) {
    String group = matcher.group();
    id.append(filename, beginIndex, matcher.start());
    id.append(converter.apply(group));
    beginIndex = matcher.end();
  }
  id.append(filename.substring(beginIndex));
  return id.toString();
}

代码示例来源:origin: hibernate/hibernate-orm

private static String insertTop(Matcher matcher, String sql, int top) {
    int end = matcher.end( 1 );

    if ( TOP_PATTERN.matcher( sql.substring( end ) ).matches() ) {
      return sql;
    }

    StringBuilder sb = new StringBuilder( sql );
    sb.insert( end, "top " + top + " " );
    return sb.toString();
  }
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Override
boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) {
  final Matcher matcher = pattern.matcher(source.substring(pos.getIndex()));
  if (!matcher.lookingAt()) {
    pos.setErrorIndex(pos.getIndex());
    return false;
  }
  pos.setIndex(pos.getIndex() + matcher.end(1));
  setCalendar(parser, calendar, matcher.group(1));
  return true;
}

代码示例来源:origin: gocd/gocd

public Set<String> getCardNumbersFromComment() {
  Set<String> cardNumbers = new TreeSet<>();
  Pattern pattern = Pattern.compile("#(\\d+)");
  String comment = this.comment == null ? "" : this.comment;
  Matcher matcher = pattern.matcher(comment);
  while (hasMatch(matcher)) {
    cardNumbers.add(id(matcher));
    matcher.end();
  }
  return cardNumbers;
}

代码示例来源:origin: org.freemarker/freemarker

MatchWithGroups(String input, Matcher matcher) {
  matchedInputPart = input.substring(matcher.start(), matcher.end());
  final int grpCount = matcher.groupCount() + 1;
  groupsSeq = new SimpleSequence(grpCount);
  for (int i = 0; i < grpCount; i++) {
    groupsSeq.add(matcher.group(i));
  }
}

代码示例来源:origin: stackoverflow.com

public static void printMatches(String text, String regex) {
  Pattern pattern = Pattern.compile(regex);
  Matcher matcher = pattern.matcher(text);
  // Check all occurrences
  while (matcher.find()) {
    System.out.print("Start index: " + matcher.start());
    System.out.print(" End index: " + matcher.end());
    System.out.println(" Found: " + matcher.group());
  }
}

代码示例来源:origin: square/okhttp

Matcher typeSubtype = TYPE_SUBTYPE.matcher(string);
if (!typeSubtype.lookingAt()) {
 throw new IllegalArgumentException("No subtype found for: \"" + string + '"');
String type = typeSubtype.group(1).toLowerCase(Locale.US);
String subtype = typeSubtype.group(2).toLowerCase(Locale.US);
Matcher parameter = PARAMETER.matcher(string);
for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) {
 parameter.region(s, string.length());
 if (!parameter.lookingAt()) {
 String name = parameter.group(1);
 if (name == null || !name.equalsIgnoreCase("charset")) continue;
 String charsetParameter;

代码示例来源:origin: Graylog2/graylog2-server

@Override
protected Result[] run(String value) {
  final Matcher matcher = pattern.matcher(value);
  if (!matcher.find() || matcher.groupCount() == 0 || matcher.start(1) == -1 || matcher.end(1) == -1) {
    return null;
  }
  return new Result[] { new Result(value.substring(matcher.start(1), matcher.end(1)), matcher.start(1), matcher.end(1)) };
}

代码示例来源:origin: apache/kafka

private static List<KerberosRule> parseRules(String defaultRealm, List<String> rules) {
  List<KerberosRule> result = new ArrayList<>();
  for (String rule : rules) {
    Matcher matcher = RULE_PARSER.matcher(rule);
    if (!matcher.lookingAt()) {
      throw new IllegalArgumentException("Invalid rule: " + rule);
    }
    if (rule.length() != matcher.end())
      throw new IllegalArgumentException("Invalid rule: `" + rule + "`, unmatched substring: `" + rule.substring(matcher.end()) + "`");
    if (matcher.group(2) != null) {
      result.add(new KerberosRule(defaultRealm));
    } else {
      result.add(new KerberosRule(defaultRealm,
          Integer.parseInt(matcher.group(5)),
          matcher.group(6),
          matcher.group(8),
          matcher.group(10),
          matcher.group(11),
          "g".equals(matcher.group(12)),
          "L".equals(matcher.group(13))));
    }
  }
  return result;
}

代码示例来源:origin: google/j2objc

@Override
public void describeTo(Description description) {
  java.util.regex.Matcher arg = ARG_PATTERN.matcher(descriptionTemplate);
  
  int textStart = 0;
  while (arg.find()) {
    description.appendText(descriptionTemplate.substring(textStart, arg.start()));
    description.appendValue(values[parseInt(arg.group(1))]);
    textStart = arg.end();
  }
  
  if (textStart < descriptionTemplate.length()) {
    description.appendText(descriptionTemplate.substring(textStart));
  }
}

代码示例来源:origin: apache/kafka

private static List<Rule> parseRules(List<String> rules) {
  rules = joinSplitRules(rules);
  List<Rule> result = new ArrayList<>();
  for (String rule : rules) {
    Matcher matcher = RULE_PARSER.matcher(rule);
    if (!matcher.lookingAt()) {
      throw new IllegalArgumentException("Invalid rule: " + rule);
    }
    if (rule.length() != matcher.end()) {
      throw new IllegalArgumentException("Invalid rule: `" + rule + "`, unmatched substring: `" + rule.substring(matcher.end()) + "`");
    }
    if (matcher.group(2) != null) {
      result.add(new Rule());
    } else {
      result.add(new Rule(matcher.group(5),
                matcher.group(6),
                "L".equals(matcher.group(7)),
                "U".equals(matcher.group(7))));
    }
  }
  return result;
}

代码示例来源:origin: hankcs/HanLP

public static FeatureTemplate create(String template)
{
  FeatureTemplate featureTemplate = new FeatureTemplate();
  featureTemplate.delimiterList = new LinkedList<String>();
  featureTemplate.offsetList = new ArrayList<int[]>(3);
  featureTemplate.template = template;
  Matcher matcher = pattern.matcher(template);
  int start = 0;
  while (matcher.find())
  {
    featureTemplate.delimiterList.add(template.substring(start, matcher.start()));
    start = matcher.end();
    featureTemplate.offsetList.add(new int[]{Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))});
  }
  return featureTemplate;
}

代码示例来源:origin: looly/hutool

@Override
boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) {
  final Matcher matcher = pattern.matcher(source.substring(pos.getIndex()));
  if (!matcher.lookingAt()) {
    pos.setErrorIndex(pos.getIndex());
    return false;
  }
  pos.setIndex(pos.getIndex() + matcher.end(1));
  setCalendar(parser, calendar, matcher.group(1));
  return true;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Expand URI template variables in the target URL with either model
 * attribute values or as a fallback with URI variable values from the
 * current request. Values are encoded.
 */
protected StringBuilder expandTargetUrlTemplate(String targetUrl,
    Map<String, Object> model, Map<String, String> uriVariables) {
  Matcher matcher = URI_TEMPLATE_VARIABLE_PATTERN.matcher(targetUrl);
  boolean found = matcher.find();
  if (!found) {
    return new StringBuilder(targetUrl);
  }
  StringBuilder result = new StringBuilder();
  int endLastMatch = 0;
  while (found) {
    String name = matcher.group(1);
    Object value = (model.containsKey(name) ? model.get(name) : uriVariables.get(name));
    Assert.notNull(value, () -> "No value for URI variable '" + name + "'");
    result.append(targetUrl.substring(endLastMatch, matcher.start()));
    result.append(encodeUriVariable(value.toString()));
    endLastMatch = matcher.end();
    found = matcher.find();
  }
  result.append(targetUrl.substring(endLastMatch, targetUrl.length()));
  return result;
}

代码示例来源:origin: looly/hutool

@Override
boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) {
  final Matcher matcher = pattern.matcher(source.substring(pos.getIndex()));
  if (!matcher.lookingAt()) {
    pos.setErrorIndex(pos.getIndex());
    return false;
  }
  pos.setIndex(pos.getIndex() + matcher.end(1));
  setCalendar(parser, calendar, matcher.group(1));
  return true;
}

代码示例来源:origin: perwendel/spark

protected final String[] parseKey(String key) {
  Matcher m = KEY_PATTERN.matcher(key);
  if (m.find()) {
    return new String[] {cleanKey(m.group()), key.substring(m.end())};
  } else {
    return null; // NOSONAR
  }
}

代码示例来源:origin: ronmamo/reflections

int findFirstMatchOfDeployableExtention(String path, int pos) {
  Pattern p = Pattern.compile("\\.[ejprw]ar/");
  Matcher m = p.matcher(path);
  if (m.find(pos)) {
    return m.end();
  } else {
    return -1;
  }
}

代码示例来源:origin: k9mail/k-9

public static List<String> extractMessageIds(final String text) {
  List<String> messageIds = new ArrayList<>();
  Matcher matcher = MESSAGE_ID.matcher(text);
  int start = 0;
  while (matcher.find(start)) {
    String messageId = text.substring(matcher.start(), matcher.end());
    messageIds.add(messageId);
    start = matcher.end();
  }
  return messageIds;
}

代码示例来源:origin: org.hamcrest/hamcrest-all

@Override
public void describeTo(Description description) {
  java.util.regex.Matcher arg = ARG_PATTERN.matcher(descriptionTemplate);
  
  int textStart = 0;
  while (arg.find()) {
    description.appendText(descriptionTemplate.substring(textStart, arg.start()));
    description.appendValue(values[parseInt(arg.group(1))]);
    textStart = arg.end();
  }
  
  if (textStart < descriptionTemplate.length()) {
    description.appendText(descriptionTemplate.substring(textStart));
  }
}

相关文章