Package org.apache.regexp

Examples of org.apache.regexp.RE


   */
  public static String parseNum(String src) {
    String result = null;
    final String rule = "[0-9��һ�����������߰˾�ʮҼ��������½��ƾ�ʰ]+";
    if (src != null) {
      RE re = new RE(rule);
      if (re.match(src)) {
        result = re.getParen(0);
      }
    }
    return result;
  }
View Full Code Here


   *         <code>mask</code>.
   */
  public static boolean isLike(String string, String mask, boolean ignoreCase) {
    try {
      // ? --> .
      RE re = new RE("\\?");
      String a = re.subst(mask, ".");
      // * --> .*
      re = new RE("\\*");
      String b = re.subst(a, ".*");
      // % --> .*
      re = new RE("\\%");
      String c = re.subst(b, ".*");
      // end with $ if started with .*
      if (c.startsWith(".*")) {
        c = c + "$";
      }
      // start with ^ if ended with .*
      if (c.endsWith(".*")) {
        c = "^" + c;
      }
      // choose level according to case insensitivity
      re = new RE(c, ignoreCase ? RE.MATCH_CASEINDEPENDENT
          : RE.MATCH_NORMAL);
      // return the matching result of regular expression
      return re.match(string);
    } catch (RESyntaxException e) {
      throw new IllegalArgumentException(e.getMessage());
    }
  }
View Full Code Here

  private String removeQuotes(String s)
  {
    if (s == null)
      return null;

    if (new RE("^\".+\"$").match(s) || new RE("^'.+'$").match(s)
        || new RE("^\\{.+\\}$").match(s)
        || new RE("^\\(.+\\)$").match(s) || new RE("^<.+>$").match(s)
        || new RE("^\\[.+\\]$").match(s))
    {
      s = s.substring(1, s.length() - 1);
    }

    return s;
View Full Code Here

      for (int i = 0; i < DISC_REGEXS.length; i++)
      {
        String kDISC_REGEX = DISC_REGEXS[i];

        RE re = new RE(kDISC_REGEX);
        if (re.match(s.toLowerCase()))
        {

          if (re.getParenCount() < 2)
          {
            Debug.debug("Disc missing number", s);
            Debug.dumpStack(3);
            continue;
          }
          int start = re.getParenStart(0);
          int end = re.getParenEnd(0);
          String value = re.getParen(1);
          // Debug.debug("value", value);
          Number number = parseNumber(value);
          if (number == null)
          {
            Debug.debug("Disc missing value", value);
View Full Code Here

    s = TextUtils.replace(s, " .", " ");
    s = TextUtils.replace(s, "  ", " ");

    // Debug.debug("rectifyGeneric_1 b", s);

    if (new RE("^\\?+$").match(s))
    {
      // Debug.debug("discarding question...", s);
      return null;
    }
View Full Code Here

  private String removeTrackNumbers(String s, IMusicMetadata flags)
  {
    if (s == null)
      return null;

    if (new RE("^(audio)? ?track ?[- ]?[0-9][0-9]?$")
        .match(s.toLowerCase()))
    {
      if (s.toLowerCase().startsWith("audio"))
        s = s.substring(5).trim();
      parseTrackNumber(s.substring(5), flags);
      // Debug.debug("discarding track...", s);
      return null;
    }
    if (new RE("^piste ?[- ]?[0-9][0-9]?$").match(s.toLowerCase()))
    {
      parseTrackNumber(s.substring(5), flags);
      // Debug.debug("discarding track...", s);
      return null;
    }

    // Debug.debug("removeTrackNumbers 1", s);

    if (new RE("^[0-9][0-9] - ").match(s)
        || new RE("^[0-9][0-9][0-9] - ").match(s)
        || new RE("^[aAbBcCdD][0-9] - ").match(s))
    {
      // Debug.debug("attempting to strip track number...", s);
      int index = s.indexOf('-');
      if (index >= 0)
      {
        String after = s.substring(index + 1).trim();
        // Debug.debug("\t" + "after", after);
        if (after.indexOf('-') < 0) // if mutiple -'s then ignore...
        {
          parseTrackNumber(s.substring(0, index), flags);
          s = after;
        }
      }
    }

    if (new RE("^\\([0-9][0-9]\\) ").match(s)
        || new RE("^\\([abcdABCD][0-9]\\) ").match(s))
    {
      // Debug.debug("attempting to strip track number...", s);
      int index = s.indexOf(')');
      if (index >= 0)
      {
View Full Code Here

    // Debug.debug("removeYearPrefixSuffix before", s);

    if (s == null)
      return null;

    if (new RE("^\\(199[0-9]\\)").match(s)
        || new RE("^\\(200[0-9]\\)").match(s))
      s = s.substring(7);

    if (new RE("^\\( 199[0-9] \\)").match(s)
        || new RE("^\\( 200[0-9] \\)").match(s))
      s = s.substring(9);

    if (new RE("\\(199[0-9]\\)$").match(s)
        || new RE("\\(200[0-9]\\)$").match(s))
      s = s.substring(0, s.length() - 7);

    if (new RE("\\( 199[0-9] \\)$").match(s)
        || new RE("\\( 200[0-9] \\)$").match(s))
      s = s.substring(0, s.length() - 9);

    if (new RE("199[0-9] - ").match(s) || new RE("200[0-9] - ").match(s))
    {
      int index = s.indexOf('-');
      if (index >= 0)
      {
        String temp = s.substring(index + 1);
        if (temp.indexOf('-') < 0)
          s = temp;
      }
    }

    if (new RE("- 199[0-9]").match(s) || new RE(" - 200[0-9]").match(s))
    {
      int index = s.lastIndexOf('-');
      if (index >= 0)
      {
        String temp = s.substring(0, index);
View Full Code Here

  {
    if (s == null)
      return null;

    {
      if (new RE("^http://").match(s.toLowerCase()))
        return null;
      // if (new RE("^[hH][tT][tT][pP]://").match(s))
      // return null;
    }

    {
      String temp = s;
      temp = TextUtils.replace(temp, ". ", ".");

      // Debug.debug("s1", s);
      RE re = new RE("^[\\w \\-]*\\.[\\w \\.\\-]*\\.(com|net|org|edu)$");
      // re.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
      if (re.match(temp.toLowerCase()))
        return null;

      // Debug.debug("s2", s);

      // if (new RE(
View Full Code Here

      Vector featured_artists, String pattern)
  {
    if (s == null)
      return null;

    RE re = new RE(pattern);
    if (re.match(s.toLowerCase()))
    {
      // Debug.debug("\t" + "featuring match(" + pattern + ")", s);
      // String wholeExpr = re.getParen(0);
      // Debug.debug("\t" + "wholeExpr", wholeExpr);
      // String insideParens = re.getParen(1);
      // Debug.debug("\t" + "insideParens", insideParens);

      int startInside = re.getParenStart(1);
      // Debug.debug("\t" + "startInside", startInside);
      int endInside = re.getParenEnd(1);
      // Debug.debug("\t" + "endInside", endInside);

      String left = s.substring(0, startInside);
      // Debug.debug("\t" + "left", left);
      String right = s.substring(startInside, endInside);
      // Debug.debug("\t" + "right", right);
      // int pattern_length = TextUtils.replace(pattern. "\\", "\");

      int index = Integer.MAX_VALUE;
      right = right.trim();

      {
        int i = right.indexOf('.');
        if (i >= 0)
          index = Math.min(index, i);
      }
      {
        int i = right.indexOf(' ');
        if (i >= 0)
          index = Math.min(index, i);
      }
      if (index < 0)
      {
        Debug.debug("\t" + "couldn't use match(" + pattern + ")", s);
        return s;
      }
      right = right.substring(index + 1);
      if (right.endsWith(")"))
        right = right.substring(0, right.length() - 1);
      if (left.endsWith("("))
        left = left.substring(0, left.length() - 1);
      right = right.trim();

      RE re2 = new RE("(.*)(,.*)*\\&(.*)");
      if (re2.match(right))
      {
        Vector v = listToNames(re2);
        featured_artists.removeAll(v);
        featured_artists.addAll(v);
      } else
      {
        re2 = new RE("(.*)(,.*)*\\ And (.*)");
        if (re2.match(right))
        {
          Vector v = listToNames(re2);
          featured_artists.removeAll(v);
          featured_artists.addAll(v);
        } else
View Full Code Here

    try
    {
      // Debug.debug("\t"+"s", s);
      // Debug.debug("\t"+"pattern", pattern);

      RE re = REGEX_CACHE.getRegEx(pattern);
      // RE re = new RE(pattern.toLowerCase());
      // Debug.debug("prefix", prefix_pattern);
      if (!re.match(s.toLowerCase()))
        return s;
      // String match = re.getParen(0);
      // Debug.debug("match(" + pattern + ")", s);
      s = s.substring(0, re.getParenStart(0))
          + s.substring(re.getParenEnd(0));
      // Debug.debug("updating...new_name ", new_name);
      return s;
    } catch (Exception e)
    {
      Debug.debug("s", s);
View Full Code Here

TOP

Related Classes of org.apache.regexp.RE

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.