Package java.util.regex

Examples of java.util.regex.MatchResult


    Map<String, String> headers = new HashMap<String, String>();
    while (scanner.hasNext() && !(scanner.hasNext(REG_EX_BLANK_LINE))) {
      if (scanner.hasNext(REG_EX_HEADER)) {
        scanner.next(REG_EX_HEADER);
        currentLineNumber++;
        MatchResult result = scanner.match();
        if (result.groupCount() == 2) {
          String headerName = result.group(1).trim().toLowerCase(Locale.ENGLISH);
          String headerValue = result.group(2).trim();
          headers.put(headerName, headerValue);
        }
      } else {
        throw new BatchException(BatchException.INVALID_HEADER.addContent(scanner.next()));
      }
View Full Code Here


        original = super.preParse(original);
        HashMap<String, NameVersion> existingEntries = new HashMap<String, NameVersion>();
        ListIterator<String> iter = original.listIterator();
        while (iter.hasNext()) {
            String entry = iter.next().trim();
            MatchResult result = null;
            _preparse_matcher_ = _preparse_pattern_.matcher(entry);
            if (_preparse_matcher_.matches()) {
                result = _preparse_matcher_.toMatchResult();
                String name = result.group(1);
                String version = result.group(2);
                NameVersion nv = new NameVersion(name, version);
                NameVersion existing = existingEntries.get(name);
                if (null != existing) {
                    if (nv.versionNumber < existing.versionNumber) {
                        iter.remove()// removal removes from original list.
                        continue;
                    }
                }
                existingEntries.put(name, nv);
            }

        }
        // we've now removed all entries less than with less than the largest
        // version number for each name that were listed after the largest.
        // we now must remove those with smaller than the largest version number
        // for each name that were found before the largest
        while (iter.hasPrevious()) {
            String entry = iter.previous().trim();
            MatchResult result = null;
            _preparse_matcher_ = _preparse_pattern_.matcher(entry);
            if (_preparse_matcher_.matches()) {
                result = _preparse_matcher_.toMatchResult();
                String name = result.group(1);
                String version = result.group(2);
                NameVersion nv = new NameVersion(name, version);
                NameVersion existing = existingEntries.get(name);
                if (null != existing) {
                    if (nv.versionNumber < existing.versionNumber) {
                        iter.remove(); // removal removes from original list.
View Full Code Here

    s1.close ();

    // Scanner s2 = new Scanner(input);
    Scanner s2 = new Scanner (input);
    s2.findInLine ("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
    MatchResult mResult = s2.match ();
    for (i = 1; i <= mResult.groupCount (); i++)
      {
  this.myHarness.check (mResult.group (i), values[i],
            "wrong result : \"" + mResult.group (i) +
            "\" != \"" + values[i] + "\"");
  // System.out.println(mResult.group(i));
      }
    if (i != values.length)
      {
View Full Code Here

     * Uses the MatchResult to only print the substring of the line that matched.
     */
    @SuppressWarnings("unused")
    private void matchSubstring(LineNumberReader reader, String name) throws IOException {
        String line;
        MatchResult result;
        int byteCount = 0;
        int matches = 0;
        while ((matches < maxCount) && (line = reader.readLine()) != null) {
            result = match(line);
            if (result != null) {
                printMatch(line.substring(result.start(), result.end()),
                           name, reader.getLineNumber(), byteCount + result.start());
                rc = 0;
                matches++;
            }
            byteCount += line.length();
        }
View Full Code Here

                LOG.log(Level.FINE,
                        "this should not happen (calculated the valid start/length) " , ex);
            }

            Matcher matcher = pattern.matcher(segment.toString());
            MatchResult currentResult = getMatchResult(matcher, !backwards);
            if (currentResult != null) {
                updateStateAfterFound(currentResult, start);
            } else {
                updateStateAfterNotFound();
            }
View Full Code Here

            } catch (BadLocationException ex) {
                LOG.log(Level.FINE,
                        "this should not happen (calculated the valid start/length) " , ex);
            }
            Matcher matcher = pattern.matcher(segment.toString());
            MatchResult currentResult = getMatchResult(matcher, true);
            if (currentResult != null) {
                // JW: how to compare match results reliably?
                // the group().equals probably isn't the best idea...
                // better check pattern?
                if ((currentResult.start() == 0) &&
                   (!lastMatchResult.group().equals(currentResult.group()))) {
                    updateStateAfterFound(currentResult, start);
                    return true;
                }
            }
            return false;
View Full Code Here

         * @param matcher
         * @param useFirst whether or not to return after the first match is found.
         * @return <code>MatchResult</code> or null
         */
        private MatchResult getMatchResult(Matcher matcher, boolean  useFirst) {
            MatchResult currentResult = null;
            while (matcher.find()) {
                currentResult = matcher.toMatchResult();
                if (useFirst) break;
            }
            return currentResult;
View Full Code Here

        // Check each occurrence of the variable for safety
        p = Pattern.compile("([?$]" + var + ")([^\\w]|$)");
        Matcher matcher = p.matcher(command);
        while (matcher.find()) {
            MatchResult posMatch = matcher.toMatchResult();

            if (n.isLiteral()) {
                if (delims.isInsideLiteral(posMatch.start(1), posMatch.end(1))) {
                    throw new ARQException(
                            "Command string is vunerable to injection attack, variable ?"
                                    + var
                                    + " appears inside of a literal and is bound to a literal which provides a SPARQL injection attack vector");
                }
View Full Code Here

        int index = -1;
        int adj = 0;
        Matcher matcher = p.matcher(command);
        while (matcher.find()) {
            index++;
            MatchResult posMatch = matcher.toMatchResult();

            Node n = this.positionalParams.get(index);
            if (n == null)
                continue;
            this.validateSafeToInject(command, index, posMatch.start(1) + adj, n);

            String nodeStr = this.stringForNode(n, context);
            command = command.substring(0, posMatch.start() + adj) + nodeStr + command.substring(posMatch.start() + adj + 1);
            // Because we are using a matcher over the string state prior to
            // starting replacements we need to
            // track the offset adjustments to make
            adj += nodeStr.length() - 1;
        }
View Full Code Here

    Pattern pattern = Pattern.compile(regexpString, Pattern.MULTILINE | Pattern.DOTALL);
    Matcher matcher = pattern.matcher(document);
    int groupCount = matcher.groupCount();
    while (matcher.find()) {
      RegExpRuleMatch ruleMatch = new RegExpRuleMatch(this);
      MatchResult matchResult = matcher.toMatchResult();
      for (int i = 0; i <= groupCount; i++) {
        int begin = matchResult.start(i);
        int end = matchResult.end(i);
        List<Type> types = groupTypes.get(i);
        if (types != null) {
          createAnnotations(i, delta, begin, end, types, fa, matchResult, ruleMatch, stream);
        } else if (i == 0) {
          CAS cas = stream.getCas();
View Full Code Here

TOP

Related Classes of java.util.regex.MatchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.