Package java.util.regex

Examples of java.util.regex.PatternSyntaxException


            int index = indexOf(m.group(INDEX_GROUP_NAME));
            if (index >= 0) {
                index++;
            } else {
                throw new PatternSyntaxException("unknown group name", input.toString(), m.start(INDEX_GROUP_NAME));
            }

            // since we're replacing the original string being matched,
            // we have to reset the matcher so that it searches the new
            // string
View Full Code Here


        Pattern pattern = Pattern.compile( "(?s).*?([0-9]+\\.[0-9]+)(\\.([0-9]+))?.*" );

        Matcher matcher = pattern.matcher( output );
        if ( !matcher.matches() )
        {
            throw new PatternSyntaxException( "Unrecognized version of Javadoc: '" + output + "'", pattern.pattern(),
                                              pattern.toString().length() - 1 );
        }

        String version = matcher.group( 3 );
        if ( version == null )
View Full Code Here

  public static /*@Nullable*/ PatternSyntaxException regexException(String s, int groups) {
    try {
      Pattern p = Pattern.compile(s);
      int actualGroups = getGroupCount(p);
      if (actualGroups < groups) {
        return new PatternSyntaxException(regexErrorMessage(s, groups, actualGroups), s, -1);
      }
    } catch (PatternSyntaxException pse) {
      return pse;
    }
    return null;
View Full Code Here

     * @param regex The erroneous pattern
     * @param index The approximate index in the pattern of the error,
     *              or {@code -1} if the index is not known
     */
    public CheckedPatternSyntaxException(String desc, String regex, int index) {
      this(new PatternSyntaxException(desc, regex, index));
    }
View Full Code Here

  public boolean hasWildcard() {
    return hasWildcard;
  }

  private static void error(String message, String pattern, int pos) {
    throw new PatternSyntaxException(message, pattern, pos);
  }
View Full Code Here

    String[] patterns = listOfPatterns.split(SEPARATOR);
    for(String p: patterns) {
      int equalsPos = p.indexOf('=');
     
      if(equalsPos < 0 || equalsPos > (p.length() -2)) {
        throw new PatternSyntaxException(
            "pattern must be of form targ=pattern", p, -1);
      }
     
      String targ = p.substring(0, equalsPos);
      if(!targ.startsWith("tags.") && !ArrayUtils.contains(SEARCH_TARGS, targ)) {
        throw new PatternSyntaxException(
            "pattern doesn't start with recognized search target", p, -1);
      }
     
      Pattern pat = Pattern.compile(p.substring(equalsPos+1), Pattern.DOTALL);
      compiledPatterns.add(new SearchRule(pat, targ));
View Full Code Here

        in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        out = new DataOutputStream(sock.getOutputStream());
        String cmd = in.readLine();
        if(!cmd.contains(" ")) {
         
          throw new PatternSyntaxException(
              "command should be keyword pattern, but no ' ' seen", cmd, -1);
        }
        String uppercased = cmd.substring(0, cmd.indexOf(' ')).toUpperCase();
        if(RAW.equals(uppercased))
          fmt = DataFormat.Raw;
        else if(WRITABLE.equals(uppercased))
          fmt = DataFormat.Writable;
        else if(ASCII_HEADER.equals(uppercased))
          fmt = DataFormat.Header;
        else {
          throw new PatternSyntaxException("bad command '" + uppercased+
              "' -- starts with neither '"+ RAW+ "' nor '"+ WRITABLE + " nor "
              + ASCII_HEADER+"'.", cmd, -1);
        }
       
        String cmdAfterSpace = cmd.substring(cmd.indexOf(' ')+1);
View Full Code Here

    private String computeReplacementString(Pattern pattern, String originalText, String replacementText) {
        if (pattern != null) {
            try {
                return pattern.matcher(originalText).replaceFirst(replacementText);
            } catch (IndexOutOfBoundsException ex) {
                throw new PatternSyntaxException(ex.getLocalizedMessage(), replacementText, -1);
            }
        }
        return replacementText;
    }
View Full Code Here

    for (String operador: operadores)
      if (!operador.equals(""))
        if (delimiters.contains(operador))
          numOperadores++;
        else
          throw new PatternSyntaxException("the follow delimiter not defined", operador, expresion.indexOf(operador));

    // Determino expresi�n
    String patternStr = "";
    if (delimiters.size() > 1)
      for (Object delimiter: delimiters.toArray())
        patternStr += "[" + delimiter + "]";
    else
      patternStr = delimiters.get(0);
   
    // Determino operandos
    int numOperandos = 0;
    patternStr = "[" + patternStr + "]";
    String[] operandos = expresion.split(patternStr);
    for (String operando : operandos)
      if (!operando.equals("")) numOperandos++;

    // Valido la correspondencia entre operandos y operadores (cadena vacia no se procesa)
    if ((numOperandos > 0) && (numOperandos - 1 != numOperadores))
      throw new PatternSyntaxException("the following input is NOT ok", expresion, 0);
   
    for (String numStr : operandos) {
      if (numStr.equals("")) continue;
      try {
       
        int num = Integer.parseInt(numStr);
       
        if (num < 0)
          throw new PatternSyntaxException("negatives not allowed", expresion, expresion.indexOf(numStr));
        else if (num <= 1000) // the numbers bigger than 1000 should be ignored
          result += num;
       
      } catch (NumberFormatException ex) {
        // On exceptions numStr equal zero
View Full Code Here

  /**
   * Throws a {@link PatternSyntaxException}.
   */
  private PatternSyntaxException syntaxError(String desc) {
    throw new PatternSyntaxException(desc, glob, index);
  }
View Full Code Here

TOP

Related Classes of java.util.regex.PatternSyntaxException

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.