Package java.util.regex

Examples of java.util.regex.Pattern


        // TODO H2 single-quotes literal values, which is useful.
        // MySQL does not single-quote literal values so its hard to
        // differentiate a FUNCTION/VARIABLE from a literal value.

        // function / variable
        Pattern functionDefault = Pattern.compile("[^'].*[^']");
        if (functionDefault.matcher(defaultValue).matches()) {
            // hard to validate this since its in the database
            // assume it is good
            return true;
        }

        // STRING
        if (modelClass == String.class) {
            Pattern stringDefault = Pattern.compile("'(.|\\n)*'");
            return stringDefault.matcher(defaultValue).matches();
        }

        String dateRegex = "[0-9]{1,4}[-/\\.][0-9]{1,2}[-/\\.][0-9]{1,2}";
        String timeRegex = "[0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}";

        // TIMESTAMP
        if (modelClass == java.util.Date.class
                || modelClass == java.sql.Timestamp.class) {
            // this may be a little loose....
            // 00-00-00 00:00:00
            // 00/00/00T00:00:00
            // 00.00.00T00:00:00
            Pattern pattern = Pattern.compile("'" + dateRegex + "." + timeRegex + "'");
            return pattern.matcher(defaultValue).matches();
        }

        // DATE
        if (modelClass == java.sql.Date.class) {
            // this may be a little loose....
            // 00-00-00
            // 00/00/00
            // 00.00.00
            Pattern pattern = Pattern.compile("'" + dateRegex + "'");
            return pattern.matcher(defaultValue).matches();
        }

        // TIME
        if (modelClass == java.sql.Time.class) {
            // 00:00:00
            Pattern pattern = Pattern.compile("'" + timeRegex + "'");
            return pattern.matcher(defaultValue).matches();
        }

        // NUMBER
        if (Number.class.isAssignableFrom(modelClass)) {
            // strip single quotes
View Full Code Here


    IOUtilities.pipeStreams(stream, bytes);

    String version = bytes.toString();

    Pattern p = Pattern.compile("Version:.*git(\\d{8}).*");
    Matcher match = p.matcher(version);

    if (match.find()) {
      if (Integer.parseInt(match.group(1)) >= WEBIF_MINIMUM_VERSION) {
        return true;
      }
View Full Code Here

        InputStream in = con.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        Matcher matcher;
        Pattern pattern = Pattern.compile("<tr><td>(\\d+):(\\d+)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td></tr>");

        String line = reader.readLine();
        while (line != null) {

            matcher = pattern.matcher(line);
            if (matcher.find()) {
                // System.out.println("h: "+matcher.group(1)+"; m: "+matcher.group(2)+"; title: "+matcher.group(3)+"; short: "+matcher.group(4)+"; desc: "+matcher.group(5));
                int h = Integer.parseInt(matcher.group(1));
                int m = Integer.parseInt(matcher.group(2));
                String title = matcher.group(3);
View Full Code Here

                for (Iterator i = appSession.getAttributes().iterator(); i.hasNext();) {
                    String attrName = ((Attribute) i.next()).getName();

                    if (attrName != null) {
                        for (Iterator j = a.iterator(); j.hasNext();) {
                            Pattern p = (Pattern) j.next();
                            if (p.matcher(attrName).matches()) {
                                j.remove();
                            }
                        }

                        if (a.isEmpty()) {
View Full Code Here

    } catch (NullPointerException e) {
      if (!this.failSilently) throw new IllegalArgumentException(
          "Block '" + blockName + "' not found." +
              " Matches " + locateBlock(blockName));
    }
    Pattern pattern = Pattern.compile("\\{([\\w\\.]+)\\}");
    Matcher matcher = pattern.matcher(copy);
    pattern = Pattern.compile("_BLOCK_\\.(.+)");
    for (Matcher matcher2; matcher.find();)
    {
      String match = matcher.group(1);
      matcher2 = pattern.matcher(match);
      if (matcher2.find())
      {
        if (parsedBlocks.containsKey(matcher2.group(1)))
        {
          copy = copy.replaceFirst("\\{"+match+"\\}", escape(
View Full Code Here

        .matcher(fileText).matches()) {
      this.implicitMain  = true; // affects parse(block) and out()
      fileText = "<!-- BEGIN: main -->" + fileText + "<!-- END: main -->";
    }
    // END: implicit main
    Pattern pattern = Pattern.compile("<!--\\s*(BEGIN|END)\\s*:\\s*(\\w+)\\s*-->(.*?)(?=(?:<!--\\s*(?:BEGIN|END)\\s*:\\s*\\w+\\s*-->)|(?:\\s*$))", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher matcher = pattern.matcher(fileText);
    ArrayList blockNames = new ArrayList();
    String parentName = "";
    int lastlength = 0; // used in newline trimming to see if one block immediately follows the previous
    while (matcher.find())
    {
View Full Code Here

    // Insert leading and trailing characters to ensure match of full string
    rePattern.insert(0, '^');
    rePattern.append('$');

    try {
            Pattern patternRegex = Pattern.compile(rePattern.toString(), Pattern.DOTALL);
            Matcher matcher = patternRegex.matcher(search);
            return matcher.matches();
    } catch(PatternSyntaxException e) {
            throw new ExpressionEvaluationException(e, "ERR.015.006.0014", QueryPlugin.Util.getString("ERR.015.006.0014", new Object[]{pattern, e.getMessage()})); //$NON-NLS-1$ //$NON-NLS-2$
    }
  }
View Full Code Here

* @author Hans Dockter
*/
public class SystemPropertiesHandler {
    public static Map<String, String> getSystemProperties(String[] arguments) {
        Map<String, String> propertyMap = new HashMap<String, String>();
        Pattern pattern = Pattern.compile("-D([^=]*)=?(.*)");
        for (String argument : arguments) {
            Matcher matcher = pattern.matcher(argument);
            if (matcher.find()) {
                String key = matcher.group(1);
                String value = matcher.group(2);
                if (key.length() > 0) {
                    propertyMap.put(key, value);
View Full Code Here

            }
        } catch (IOException e) {
            throw new RuntimeException("Error when loading properties file=" + propertiesFile, e);
        }

        Pattern pattern = Pattern.compile("systemProp\\.(.*)");
        for (Object argument : properties.keySet()) {
            Matcher matcher = pattern.matcher(argument.toString());
            if (matcher.find()) {
                String key = matcher.group(1);
                if (key.length() > 0) {
                    propertyMap.put(key, properties.get(argument).toString());
                }
View Full Code Here

      if ( !type.endsWith("*")){
       
        type = type + ".*";
      }
     
      Pattern pattern = Pattern.compile( type );
           
      for (int i=0;i<stats_names.size();i++){
       
        String  s = (String)stats_names.get(i);
       
        if ( pattern.matcher( s ).matches()){
         
          expanded.add( s );
        }
      }
     
      Iterator provider_it = providers.iterator();
     
      while( provider_it.hasNext()){
       
        Object[]  provider_entry = (Object[])provider_it.next();
       
        Set provider_types = (Set)provider_entry[0];
       
        Iterator pt_it = provider_types.iterator();
       
        while( pt_it.hasNext()){
         
          String  s = (String)pt_it.next();
         
          if ( pattern.matcher( s ).matches()){
           
            expanded.add( s );
          }
        }
      }
View Full Code Here

TOP

Related Classes of java.util.regex.Pattern

Copyright © 2015 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.