当前位置: 首页>>代码示例>>Java>>正文


Java Matcher.group方法代码示例

本文整理汇总了Java中com.google.re2j.Matcher.group方法的典型用法代码示例。如果您正苦于以下问题:Java Matcher.group方法的具体用法?Java Matcher.group怎么用?Java Matcher.group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.re2j.Matcher的用法示例。


在下文中一共展示了Matcher.group方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialize

import com.google.re2j.Matcher; //导入方法依赖的package包/类
@Override
public DeserializedEvent deserialize(String raw) {
  Matcher m = this.pattern.matcher(raw);

  if (!m.matches()) {
    throw new DeserializationException("raw event does not match string");
  }

  int groups = m.groupCount();
  Map<String, Object> mapping = new HashMap<>(groups);
  for (int i = 0; i < groups && i < fields.size(); i++) {
    String str = m.group(i + 1);

    ReFieldConfig field = this.fields.get(i);
    mapping.put(field.getName(), RegexDeserializer.parse(str, field.getType()));
  }

  return new RegexEvent(mapping);
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:20,代码来源:Re2jRegexDeserializer.java

示例2: run

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private Set<FileState> run(Iterable<FileState> files, Console console) throws IOException, ValidationException {
  Set<FileState> modifiedFiles = new HashSet<>();
  // TODO(malcon): Remove reconstructing pattern once RE2J doesn't synchronize on matching.
  Pattern batchPattern = Pattern.compile(pattern.pattern(), pattern.flags());
  for (FileState file : files) {
    if (Files.isSymbolicLink(file.getPath())) {
      continue;
    }
    String content = new String(Files.readAllBytes(file.getPath()), UTF_8);
    Matcher matcher = batchPattern.matcher(content);
    StringBuffer sb = new StringBuffer();
    boolean modified = false;
    while (matcher.find()) {
      List<String> users = Splitter.on(",").splitToList(matcher.group(2));
      List<String> mappedUsers = mapUsers(users, matcher.group(0), file.getPath(), console);
      modified |= !users.equals(mappedUsers);
      String result = matcher.group(1);
      if (!mappedUsers.isEmpty()) {
        result += "(" + Joiner.on(",").join(mappedUsers) + ")";
      }
      matcher.appendReplacement(sb, result);
    }
    matcher.appendTail(sb);

    if (modified) {
      modifiedFiles.add(file);
      Files.write(file.getPath(), sb.toString().getBytes(UTF_8));
    }
  }
  return modifiedFiles;
}
 
开发者ID:google,项目名称:copybara,代码行数:32,代码来源:TodoReplace.java

示例3: lsTree

import com.google.re2j.Matcher; //导入方法依赖的package包/类
ImmutableList<TreeElement> lsTree(GitRevision reference, String treeish) throws RepoException {
  ImmutableList.Builder<TreeElement> result = ImmutableList.builder();
  String stdout = simpleCommand("ls-tree", reference.getSha1(), "--", treeish).getStdout();
  for (String line : Splitter.on('\n').split(stdout)) {
    if (line.isEmpty()) {
      continue;
    }
    Matcher matcher = LS_TREE_ELEMENT.matcher(line);
    if (!matcher.matches()) {
      throw new RepoException("Unexpected format for ls-tree output: " + line);
    }
    // We ignore the mode for now
    GitObjectType objectType = GitObjectType.valueOf(matcher.group(2).toUpperCase());
    String sha1 = matcher.group(3);
    String path = matcher.group(4)
        // Per ls-tree documentation. Replace those escaped characters.
        .replace("\\\\", "\\").replace("\\t", "\t").replace("\\n", "\n");

    result.add(new TreeElement(objectType, sha1, path));
  }
  return result.build();
}
 
开发者ID:google,项目名称:copybara,代码行数:23,代码来源:GitRepository.java

示例4: build

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/**
 * Returns the freshly substituted SQL code.
 *
 * @throws IllegalArgumentException if any substitution variable is not found in the template,
 *         or if there are any variable-like strings (%something%) left after substitution.
 */
public String build() {
  StringBuffer result = new StringBuffer(template.length());
  Set<String> found = new HashSet<>();
  Matcher matcher = SEARCH_PATTERN.matcher(template);
  while (matcher.find()) {
    String wholeMatch = matcher.group(0);
    String leftQuote = matcher.group(1);
    String key = matcher.group(2);
    String rightQuote = matcher.group(3);
    String value = substitutions.get(key);
    checkArgumentNotNull(value, "%%s% found in template but no substitution specified", key);
    checkArgument(leftQuote.equals(rightQuote), "Quote mismatch: %s", wholeMatch);
    matcher.appendReplacement(result, String.format("%s%s%s", leftQuote, value, rightQuote));
    found.add(key);
  }
  matcher.appendTail(result);
  Set<String> remaining = difference(substitutions.keySet(), found);
  checkArgument(remaining.isEmpty(),
      "Not found in template: %s", Joiner.on(", ").join(remaining));
  return result.toString();
}
 
开发者ID:google,项目名称:nomulus,代码行数:28,代码来源:SqlTemplate.java

示例5: extractIDString

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/**
 * Extract Date + ID + No
 * Ex: " 15/02/14(六)07:14:32 ID:F.OqpZFA No.6135732"
 * @return Post
 */
private Post extractIDString(Post post, TextNode node) {
    Pattern r = Pattern.compile("(\\d{2})/(\\d{2})/(\\d{2}).+?(\\d{2}):(\\d{2}):(\\d{2}) ID:([\\./0-9A-Za-z]+?) No\\.(\\d+)");
    Matcher m = r.matcher(node.text());
    if (m.find()) {
        Integer Y = Integer.parseInt(m.group(1)) + 2000, //year
                M = Integer.parseInt(m.group(2)) - 1, //month
                D = Integer.parseInt(m.group(3)), //day
                H = Integer.parseInt(m.group(4)), //hours
                I = Integer.parseInt(m.group(5)), //minutes
                S = Integer.parseInt(m.group(6)); //seconds
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Taipei"));
        cal.set(Y, M, D, H, I, S);
        post.date = cal;

        post.tripId = m.group(7);
        post.no = m.group(8);
    }

    return post;
}
 
开发者ID:touhonoob,项目名称:KomiReader,代码行数:26,代码来源:KomicaScraper.java

示例6: parse

import com.google.re2j.Matcher; //导入方法依赖的package包/类
@Nullable
static GerritIntegrateLabel parse(String str, GitRepository repository,
    GeneralOptions generalOptions) {
  Matcher matcher = LABEL_PATTERN.matcher(str);
  return matcher.matches()
         ? new GerritIntegrateLabel(repository, generalOptions,
                                    matcher.group(1),
                                    Integer.parseInt(matcher.group(2)),
                                    (matcher.group(3) == null
                                     ? null
                                     : Integer.parseInt(matcher.group(3))),
                                    matcher.group(4))
         : null;
}
 
开发者ID:google,项目名称:copybara,代码行数:15,代码来源:GerritIntegrateLabel.java

示例7: parse

import com.google.re2j.Matcher; //导入方法依赖的package包/类
@Nullable
static GithubPRIntegrateLabel parse(String str, GitRepository repository,
    GeneralOptions generalOptions) {
  Matcher matcher = LABEL_PATTERN.matcher(str);
  return matcher.matches()
         ? new GithubPRIntegrateLabel(repository, generalOptions,
                                      matcher.group(1),
                                      Long.parseLong(matcher.group(2)),
                                      matcher.group(3),
                                      matcher.group(4))
         : null;
}
 
开发者ID:google,项目名称:copybara,代码行数:13,代码来源:GithubPRIntegrateLabel.java

示例8: parseBookName

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private void parseBookName() {
    String fileName = this.mFile.getName();
    Matcher matcher = bookNamePattern.matcher(fileName);
    while (matcher.find()) {
        mBookName = matcher.group();
        mBookName = mBookName.substring(1, mBookName.length() - 1);
    }
    if (mBookName == null) {
        int lastIndexOfDot = fileName.lastIndexOf(".");
        if (lastIndexOfDot > 0 && lastIndexOfDot < fileName.length())
            mBookName = fileName.substring(0, lastIndexOfDot);
        else
            mBookName = fileName;
    }
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:16,代码来源:LocalTextReader.java

示例9: readCodepoint

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/**
 * Read the codepoint from a single line. The expected format of each line is:
 * {@code U+XXXX}
 * Where {@code XXXX} holds the hex value of the codepoint.
 */
private static int readCodepoint(String line) {
  Matcher matcher = LINE_PATTERN.matcher(line);
  checkArgument(matcher.lookingAt(), "Can't parse line: %s", line);

  String hexString = matcher.group(1);
  return Integer.valueOf(hexString, 16);
}
 
开发者ID:google,项目名称:nomulus,代码行数:13,代码来源:IdnTable.java

示例10: mapUsers

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private List<String> mapUsers(List<String> users, String rawText, Path path, Console console)
    throws ValidationException {
  Set<String> alreadyAdded = new HashSet<>();
  List<String> result = new ArrayList<>();
  for (String rawUser : users) {
    Matcher matcher = SINGLE_USER_PATTERN.matcher(rawUser);
    // Throw VE if the pattern doesn't match and mode is MAP_OR_FAIL
    if (!matcher.matches()) {
      if (mode == Mode.MAP_OR_FAIL) {
        throw new ValidationException(String.format(
            "Unexpected '%s' doesn't match expected format", rawUser));
      } else {
        console.warnFmt("Skipping '%s' that doesn't match expected format", rawUser);
        continue;
      }
    }
    String prefix = matcher.group(1);
    String originUser = matcher.group(2);
    String suffix = matcher.group(3);
    switch (mode) {
      case MAP_OR_FAIL:
        checkCondition(mapping.containsKey(originUser),
            "Cannot find a mapping '%s' in '%s' (%s)", originUser, rawText, path);
        // fall through
      case MAP_OR_IGNORE:
        String destUser = mapping.getOrDefault(originUser, originUser);
        if (alreadyAdded.add(destUser)) {
          result.add(prefix + destUser + suffix);
        }
        break;
      case MAP_OR_DEFAULT:
        destUser = mapping.getOrDefault(originUser, defaultString);
        if (alreadyAdded.add(destUser)) {
          result.add(prefix + destUser + suffix);
        }
        break;
      case SCRUB_NAMES:
        break;
      case USE_DEFAULT:
        if (alreadyAdded.add(defaultString)) {
          result.add(prefix + defaultString + suffix);
        }
        break;
    }
  }
  return result;
}
 
开发者ID:google,项目名称:copybara,代码行数:48,代码来源:TodoReplace.java

示例11: replaceLine

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private String replaceLine(String line) {
  if (patternsToIgnore != null) {
    for (Pattern patternToIgnore : patternsToIgnore) {
      if (patternToIgnore.matches(line)) {
        return line;
      }
    }
  }

  Matcher matcher = before.matcher(line);
  StringBuffer sb = new StringBuffer();
  while (matcher.find()) {
    for (Collection<Integer> groupIndexes : repeatedGroups.asMap().values()) {
      // Check that all the references of the repeated group match the same string
      Iterator<Integer> iterator = groupIndexes.iterator();
      String value = matcher.group(iterator.next());
      while (iterator.hasNext()) {
        if (!value.equals(matcher.group(iterator.next()))) {
          return line;
        }
      }
    }
    String replaceTemplate;
    if (callback != null) {
      ImmutableMap.Builder<Integer, String> groupValues =
          ImmutableMap.builder();
      for (int i = 0; i <= matcher.groupCount(); i++) {
        groupValues.put(i, matcher.group(i));
      }
      replaceTemplate = callback.alter(groupValues.build(), afterReplaceTemplate);
    } else {
      replaceTemplate = afterReplaceTemplate;
    }

    matcher.appendReplacement(sb, replaceTemplate);
    if (firstOnly) {
      break;
    }
  }
  matcher.appendTail(sb);
  return sb.toString();
}
 
开发者ID:google,项目名称:copybara,代码行数:43,代码来源:TemplateTokens.java

示例12: extractHtmlTitle

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/** Returns the contents of the title tag in the given HTML, or null if not found. */
private static String extractHtmlTitle(String html) {
  Matcher matcher = HTML_TITLE_TAG_PATTERN.matcher(html);
  return (matcher.find() ? matcher.group(1) : null);
}
 
开发者ID:google,项目名称:nomulus,代码行数:6,代码来源:AppEngineConnection.java

示例13: testDomainTransferPollMessage_serverApproved

import com.google.re2j.Matcher; //导入方法依赖的package包/类
@Test
public void testDomainTransferPollMessage_serverApproved() throws Exception {
  // As the losing registrar, create the domain.
  assertCommandAndResponse("login_valid.xml", "login_response.xml");
  createFakesite();
  assertCommandAndResponse("logout.xml", "logout_response.xml");

  // As the winning registrar, request a transfer. Capture the server trid; we'll need it later.
  assertCommandAndResponse("login2_valid.xml", "login_response.xml");
  String response =
      assertCommandAndResponse(
          "domain_transfer_request_1_year.xml",
          "domain_transfer_response_1_year.xml",
          DateTime.parse("2001-01-01T00:00:00Z"));
  Matcher matcher = Pattern.compile("<svTRID>(.*)</svTRID>").matcher(response);
  matcher.find();
  String transferRequestTrid = matcher.group(1);
  assertCommandAndResponse("logout.xml", "logout_response.xml");

  // As the losing registrar, read the request poll message, and then ack it.
  assertCommandAndResponse("login_valid.xml", "login_response.xml");
  assertCommandAndResponse(
      "poll.xml",
      "poll_response_domain_transfer_request.xml",
      DateTime.parse("2001-01-01T00:01:00Z"));
  assertCommandAndResponse(
      "poll_ack.xml",
      ImmutableMap.of("ID", "1-C-EXAMPLE-17-23-2001"),
      "poll_ack_response_empty.xml",
      null,
      DateTime.parse("2001-01-01T00:01:00Z"));

  // Five days in the future, expect a server approval poll message to the loser, and ack it.
  assertCommandAndResponse(
      "poll.xml",
      "poll_response_domain_transfer_server_approve_loser.xml",
      DateTime.parse("2001-01-06T00:01:00Z"));
  assertCommandAndResponse(
      "poll_ack.xml",
      ImmutableMap.of("ID", "1-C-EXAMPLE-17-22-2001"),
      "poll_ack_response_empty.xml",
      null,
      DateTime.parse("2001-01-06T00:01:00Z"));
  assertCommandAndResponse("logout.xml", "logout_response.xml");

  // Also expect a server approval poll message to the winner, with the transfer request trid.
  assertCommandAndResponse("login2_valid.xml", "login_response.xml");
  assertCommandAndResponse(
      "poll.xml",
      null,
      "poll_response_domain_transfer_server_approve_winner.xml",
      ImmutableMap.of("SERVER_TRID", transferRequestTrid),
      DateTime.parse("2001-01-06T00:02:00Z"));
  assertCommandAndResponse(
      "poll_ack.xml",
      ImmutableMap.of("ID", "1-C-EXAMPLE-17-21-2001"),
      "poll_ack_response_empty.xml",
      null,
      DateTime.parse("2001-01-06T00:02:00Z"));
  assertCommandAndResponse("logout.xml", "logout_response.xml");
}
 
开发者ID:google,项目名称:nomulus,代码行数:62,代码来源:EppLifecycleDomainTest.java


注:本文中的com.google.re2j.Matcher.group方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。