Package java.util.regex

Examples of java.util.regex.MatchResult.groupCount()


        assertEquals(0, result.start());
        assertEquals(4, result.end());
        assertEquals(0, result.start(0));
        assertEquals(4, result.end(0));
        assertEquals("True", result.group());
        assertEquals(0, result.groupCount());
       
    }
    
    /**
     * @throws IOException
View Full Code Here


        assertEquals(3, result.end());
        assertEquals(2, result.start(0));
        assertEquals(3, result.end(0));
        assertEquals("2", result.group());
        assertEquals("2", result.group(0));
        assertEquals(0, result.groupCount());
        try {
            result.start(1);
            fail("should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            // Expected
View Full Code Here

        Scanner scanner = new Scanner( new ByteArrayInputStream( message.getBytes() ) );
        String foundString = scanner.findWithinHorizon( ".*line (\\d+):(\\d+): *([^\\n]*).*", message.length() );
        if ( foundString != null )
        {
            MatchResult result = scanner.match();
            if ( result.groupCount() == 3 )
            {
                ExceptionMessage exceptionMessage = new ExceptionMessage();
                exceptionMessage.lineNumber = result.group( 1 );
                exceptionMessage.columnNumber = result.group( 2 );
                exceptionMessage.cause = result.group( 3 );
View Full Code Here

        Scanner scanner = new Scanner(text);
        String versionNums = scanner.findWithinHorizon("(\\d+)(\\.\\d+)(\\.\\d+)?", 0);
        String version = "";
        if (versionNums != null) {
            MatchResult groups = scanner.match();
            for (int i = 1; i <= groups.groupCount() && groups.group(i) != null; i++) // yes, truly 1-indexed
                version += groups.group(i);
        }
        return version;
    }
View Full Code Here

  static void useRegex() {
    String input = "1 fish 2 fish red fish blue fish";
    Scanner s = new Scanner(input);
    s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
    MatchResult result = s.match();
    for (int i=1; i<=result.groupCount(); i++)
      System.out.println(result.group(i));
    s.close();
  }

  static void readFile() {
View Full Code Here

    public Object[] getParametersFromMethodString(String methodString) throws Exception {
        List<Object> params = new ArrayList<Object>();
        Matcher matcher = getMatcherFor(methodString);
        if (matches(matcher)) {
            MatchResult matchResult = matcher.toMatchResult();
            for (int index = 1; index <= matchResult.groupCount(); index++) {
                params.add(matchResult.group(index));
            }
        }
        return parser.convertParamertersToTypes(
                params.toArray(new Object[params.size()]), method.getParameterTypes());
View Full Code Here

    @Override
    protected String group(int index, int groupNumber) {
        MatchResult result = getMatch(index);

        if (groupNumber <= result.groupCount()) {
            return result.group(groupNumber);
        }

        return null;
    }
View Full Code Here

    @Override
    protected String group(int index, int groupNumber) {
        MatchResult result = getMatch(index);

        if (groupNumber <= result.groupCount()) {
            return result.group(groupNumber);
        }

        return null;
    }
View Full Code Here

    @Override
    protected String group(int index, int groupNumber) {
        MatchResult result = getMatch(index);

        if (0 <= groupNumber && groupNumber <= result.groupCount()) {
            return result.group(groupNumber);
        }

        return null;
    }
View Full Code Here

      scanner.next(REG_EX_REQUEST_LINE);
      currentLineNumber++;
      final String method;
      final String uri;
      MatchResult result = scanner.match();
      if (result.groupCount() == 2) {
        method = result.group(1);
        uri = result.group(2).trim();
      } else {
        currentLineNumber++;
        throw new BatchException(BatchException.INVALID_REQUEST_LINE.addContent(scanner.next()).addContent(
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.