Package java.util.regex

Examples of java.util.regex.Matcher


    String pre = "\\$\\{";
    String post = "\\}";
    String regex = pre+"(.*?)"+post;
    Pattern pattern = Pattern.compile(regex);

    Matcher matcher = pattern.matcher(value);

    while (matcher.find()) {
      String sysKey = matcher.group(1);
      String p = pre + sysKey + post;
      String v = sysKey.equalsIgnoreCase("user.appdata") ? System.getenv("appdata") : System.getProperty(sysKey,"UNKNOWN");
     
      // We habe to replace '\' and '$' signs before replacement
      // see: http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Matcher.html#replaceAll(java.lang.String)


  }

  private SoftwareUpdateItem[] readSoftwareUpdateItems(BufferedReader reader, boolean onlyUpdates, boolean dragNdrop, PluginBaseInfo[] baseInfos) throws IOException {
    Pattern pluginTypePattern = Pattern.compile("\\[(.*):(.*)\\]");
    Pattern keyValuePattern = Pattern.compile("(.+?)=(.*)");
    Matcher matcher;

    ArrayList<SoftwareUpdateItem> updateItems = new ArrayList<SoftwareUpdateItem>();
    //ArrayList<PluginsSoftwareUpdateItem> blockedItems = new ArrayList<PluginsSoftwareUpdateItem>(0);

    try {
      SoftwareUpdateItem curItem=null;
      String line=reader.readLine();

      while (line != null) {
        matcher=pluginTypePattern.matcher(line);
        if (matcher.find()) { // new plugin
          String type=matcher.group(1);
          String className=matcher.group(2);

          if ("plugin".equals(type)) {
            curItem=new PluginSoftwareUpdateItem(className);
          }
          else if ("dataservice".equals(type)) {
            curItem=new DataServiceSoftwareUpdateItem(className);
          }
          else if ("tvbrowser".equals(type)) {
            curItem=new TvbrowserSoftwareUpdateItem(className);
          }

          if (curItem==null) {
            throw new IOException("invalid software update file");
          }

          updateItems.add(curItem);
        }
        else {
          matcher=keyValuePattern.matcher(line);

          if (matcher.find()) { // new plugin
            String value = matcher.group(2);
            value = value.replaceAll("\\\\", ""); // fix wrong HTML encoding in plugin descriptions

            if(curItem != null) {
              curItem.addProperty(matcher.group(1), value);
            }
          }
        }
        line=reader.readLine();
      }

        if (value.toLowerCase().indexOf(preFilter) < 0) {
          return false;
        }
      }
      // second step: regex search
      Matcher matcher = mPattern.matcher(value);
      return matcher.matches();
    }
  }

     * Mask the password of the connection url with ***
     * @param url the actual url
     * @return the masked url
     */
    public static String maskURLPassword(String url) {
        final Matcher urlMatcher = URL_PATTERN.matcher(url);
        String maskUrl;
        if (urlMatcher.find()) {
            final Matcher pwdMatcher = PASSWORD_PATTERN.matcher(url);
            maskUrl = pwdMatcher.replaceFirst("\":***@\"");
            return maskUrl;
        }
        return url;
    }

    public static String methodNameToAttributeName(String methodName) {
        methodName=methodName.startsWith("get") || methodName.startsWith("set")? methodName.substring(3): methodName;
        methodName=methodName.startsWith("is")? methodName.substring(2) : methodName;
        // Pattern p=Pattern.compile("[A-Z]+");
        Matcher m=METHOD_NAME_TO_ATTR_NAME_PATTERN.matcher(methodName);
        StringBuffer sb=new StringBuffer();
        while(m.find()) {
            int start=m.start(), end=m.end();
            String str=methodName.substring(start, end).toLowerCase();
            if(str.length() > 1) {
                String tmp1=str.substring(0, str.length() -1);
                String tmp2=str.substring(str.length() -1);
                str=tmp1 + "_" + tmp2;
            }
            if(start == 0) {
                m.appendReplacement(sb, str);
            }
            else
                m.appendReplacement(sb, "_" + str);
        }
        m.appendTail(sb);
        return sb.toString();
    }


    public static String attributeNameToMethodName(String attr_name) {
        if(attr_name.contains("_")) {
            // Pattern p=Pattern.compile("_.");
            Matcher m=ATTR_NAME_TO_METHOD_NAME_PATTERN.matcher(attr_name);
            StringBuffer sb=new StringBuffer();
            while(m.find()) {
                m.appendReplacement(sb, attr_name.substring(m.end() - 1, m.end()).toUpperCase());
            }
            m.appendTail(sb);
            char first=sb.charAt(0);
            if(Character.isLowerCase(first)) {
                sb.setCharAt(0, Character.toUpperCase(first));
            }
            return sb.toString();

              .getIterator(HTML.Tag.CONTENT); it.isValid(); it.next()) {
            try {
              String fragment = document.getText(it.getStartOffset(), it
                  .getEndOffset()
                  - it.getStartOffset());
              Matcher matcher = pattern.matcher(fragment);
              while (matcher.find()) {
                highlighter.addHighlight(it.getStartOffset() + matcher.start(),
                    it.getStartOffset() + matcher.end(), painter);
              }
            } catch (BadLocationException ex) {
            }
          }
        }

     * Method for validating event strings against event string specifications, where a
     * specification is a regular expression involving event symbols. e.g. [b]([sgv])[u]
     */
    protected static boolean validateEventString(String eventString, String spec) {
        Pattern pattern = null;
        Matcher matcher = null;

        // set up the regular expression specification
        pattern = Pattern.compile(spec);
        // set up the actual event string
        matcher = pattern.matcher(eventString);

        // check if the actual string satisfies the specification
        if (matcher.find()) {
            // a match has been found, but we need to check that the whole event string
            // matches, and not just a substring
            if (!(matcher.start() == 0 && matcher.end() == eventString.length())) {
                // match on full eventString not found
                System.err
                                .println("event string invalid (proper substring matched): event string = "
                                                + eventString
                                                + ", specification = "
                                                + spec
                                                + "matcher.start() "
                                                + matcher.start()
                                                + " matcher.end() " + matcher.end());
                return false;
            }
        } else {
            return false;
        }

    Pattern p = Pattern.compile("get([A-Z]\\w+)");
   
    for (int i = 0; i < m.length; i++) {
      if (m[i].getName().equals("getClass")) continue;
      if (m[i].getParameterTypes().length > 0) continue;
      Matcher r = p.matcher(m[i].getName());
      if (r.matches()) {
        try {
          values.put(r.group(1).toLowerCase(), m[i].invoke(bean, new Object[0]));
        } catch (IllegalArgumentException e) {
          throw e;
        } catch (IllegalAccessException e) {
          throw new RuntimeException(e);
        } catch (InvocationTargetException e) {

        public Object put(Object key, Object value) {
            if (key instanceof String) {
                String name = (String) key;
                int bracket = name.indexOf('[');
                if (bracket > -1 && name.endsWith("]")) {
                    Matcher matcher = paramPattern.matcher(name);
                    String partName = name.substring(0, bracket);
                    return putInternal(partName, matcher, value);
                }
            }
            Object previous = super.get(key);

TOP

Related Classes of java.util.regex.Matcher

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.