Package gnu.regexp

Examples of gnu.regexp.RE


    return pattern == pubSessionId;
  }

   private static boolean matchesRegex(String pattern, String txt) {
      try {
         RE regex = new RE(pattern, RE.REG_ICASE);
         return regex.isMatch(txt);
      }
      catch (REException ex) {
         ex.printStackTrace();
         return false;
      }
View Full Code Here


  private static RE RE_TimeLimitAction;

public  FormatChecker () {

  try {
    RE_CMIBlank = new RE ("", RE.REG_NOTEOL);
    RE_CMIBoolean = new RE ("^(true|false)$", RE.REG_NOTEOL);
    RE_CMIDecimal = new RE ("^[-+]??(\\d+)??(\\.)??(\\d)+$", RE.REG_NOTEOL);
    RE_CMIIdentifier = new RE ("^\\S{1,255}$", RE.REG_NOTEOL);
    RE_CMIInteger = new RE ("^\\d{1,5}$", RE.REG_NOTEOL);
    RE_CMISInteger = new RE ("^[-+]??\\d{1,5}$", RE.REG_NOTEOL);
    RE_CMIString255 = new RE ("^[\\S\\s]{0,255}$", RE.REG_NOTEOL);
    RE_CMIString4096 = new RE ("^[\\S\\s]{0,4096}$", RE.REG_NOTEOL);
    RE_CMITime = new RE ("^(0[0-9]|1[0-9]|2[1-3]):[0-5]\\d:[0-5]\\d(\\.((\\d)|(\\d\\d)))*$", RE.REG_NOTEOL);
    RE_CMITimespan = new RE ("^(\\d){2,4}:(\\d\\d)\\:(\\d\\d)((\\.)((\\d)|(\\d\\d)))*$", RE.REG_NOTEOL);

    RE_choice = new RE ("^([a-z\\d])?((,)([a-z\\d]))*$|^{([a-z\\d])??((,)([a-z\\d]))*}$", RE.REG_NOTEOL);
    RE_fill_in = new RE ("^[\\S\\s]{0,255}$", RE.REG_NOTEOL);
    RE_likert = new RE ("^[a-z0-9]?$", RE.REG_NOTEOL);
    //RE_matching = new RE ("^([a-z\\d]\\.[a-z\\d])??(,([a-z\\d]\\.[a-z\\d]))*$|^{([a-z\\d]\\.[a-z\\d])??(,([a-z\\d]\\.[a-z\\d]))*}$", RE.REG_NOTEOL);
    RE_matching = new RE ("^([a-zA-Z\\d]+\\.[a-zA-Z\\d])??(,([a-zA-Z\\d]+\\.[a-zA-Z\\d]))*$|^{([a-zA-Z\\d]+\\.[a-zA-Z\\d])??(,([a-zA-Z\\d]+\\.[a-zA-Z\\d]))*}$", RE.REG_NOTEOL);
    RE_numeric = new RE ("^[-+]??(\\d+)??(\\.)??(\\d)+$", RE.REG_NOTEOL);
    RE_performance = new RE ("^[\\S\\s]{0,255}$", RE.REG_NOTEOL);
    RE_sequencing = new RE ("^([a-z\\d])??(,[a-z\\d])*$", RE.REG_NOTEOL);
    RE_true_false = new RE ("^(t|f|0|1)$", RE.REG_NOTEOL);

    RE_Credit = new RE ("^(credit|no-credit)$", RE.REG_NOTEOL);
    RE_Entry = new RE ("^(ab-initio|resume)??$", RE.REG_NOTEOL);
    RE_Exit = new RE ("^(time-out|suspend|logout)??$", RE.REG_NOTEOL);
    RE_Interaction = new RE ("^(true-false|choice|fill-in|matching|performance|likert|sequencing|numeric)$", RE.REG_NOTEOL);
    RE_Mode = new RE ("^(normal|review|browse)$", RE.REG_NOTEOL);
    RE_Result = new RE ("^(correct|wrong|unanticipated|neutral|([+-]?\\d+)\\.?\\d*)$", RE.REG_NOTEOL);
    RE_Status = new RE ("^(passed|completed|failed|incomplete|browsed|not attempted)$", RE.REG_NOTEOL);
    RE_TimeLimitAction = new RE ("^(exit,message|exit,no message|continue,message|continue,no message)$", RE.REG_NOTEOL);

  } catch (Exception e) {/**/}

  regexpFeedback.put ("choice", RE_choice);
  regexpFeedback.put ("fill-in", RE_fill_in);
View Full Code Here

public  void setFeedbackType (String fb) {

  RE_Feedback = null;

  if (!fb.equals("")) {
    RE o = regexpFeedback.get (fb);
    if (o != null) {
      RE_Feedback = o;
    }
  }
}
View Full Code Here

  }
}

public  boolean check (String el, String val) {

  RE tr;
  if (el.equals("cmi.interactions.n.correct_responses.n.pattern") ||
      el.equals("cmi.interactions.n.student_response") ){
    tr = RE_Feedback;
  } else {
    tr = regexp.get (el);
  }

  if (tr == null) return false;

  if (tr.getMatch (val) != null) return true;

  return false;
}
View Full Code Here

 
 
  public  ExpressionView()
  {
    try{
       mReIsWhitespace = new RE("^\\s*$",0, RESyntax.RE_SYNTAX_PERL5);
      }catch(Exception e) {System.out.println(e);}
    mCommandCount = 1;
     
  }
View Full Code Here

        Enumeration names = regexpSet.propertyNames();
        int ex = 0;
        while (names.hasMoreElements()) {
          String exp = (String) names.nextElement();
          RE re = null;
          try {
            re = new RE(exp);
          } catch (Exception e) {
            System.err.println("Something wrong with regexp: " +
                               ex + "\t" + exp);
            System.err.println(e);
          }
View Full Code Here

      if (line[lp] == '\n') {
        String l = new String(line, 0, lp + 1);
        boolean colored = false;
        boolean useexp = (exps != null);
        for (int ex = 0; !colored && useexp && ex < exps.length; ex += 2) {
          RE exp = (RE) exps[ex];
          if (null != exp.getMatch(l)) {
            byte[] color = (byte[]) ((String) exps[ex + 1]).getBytes();
            System.arraycopy(color, 0, nbuf, nbufptr, color.length);
            nbufptr += color.length;
            System.arraycopy(line, 0, nbuf, nbufptr, lp + 1);
            nbufptr += lp + 1;
View Full Code Here

    if (multilineCheckBox.getSelection()) {
      eflags |= RE.REG_MULTILINE;
    }

    try {
      RE re = new RE(regExpText.getText(), eflags);

      REMatch[] matches = re.getAllMatches(matchText.getText());

      result = matches.length > 0 ? true : false;

      // Reset style
      matchText.setStyleRange(null);

      for (int i = 0; i < matches.length; i++) {
        int color = 0;
        for (int j = 1; j <= re.getNumSubs(); j++) {

          StyleRange styleRange = new StyleRange();

          styleRange.start = matches[i].getStartIndex(j);
          styleRange.length = matches[i].getEndIndex(j)
View Full Code Here

  }

  private void buildDebugRegExp(String input, String match) {
    String convInput;
    String result = "";
    RE re = null;
    boolean inBracket = false;
    boolean escape = false;
    String character;
    int start = 0, end = 0;
    int bracketStart = 0;

    debugInfo = new DebugInfo();
    debugInfo.setInput(input);
    debugInfo.setMatchString(match);

    try {
      // Replace escaped characters
      re = new RE("\\[^.]");
      convInput = re.substitute(input, "..");

      if (convInput.indexOf('(') == -1) {
        for (int i = 0; i < input.length(); i++) {
          character = input.substring(i, i + 1);

          if (!inBracket) {
            re = new RE("[\\[\\{]");
            if (re.isMatch(character)) {
              bracketStart = result.length();
              result += "(" + character;
              inBracket = true;
              start = i;
            } else {
              if (!escape) {
                bracketStart = result.length();
                result += "(";
                start = i;
              } else {
                escape = false;
              }

              result += character;
              if (character.equals("\\")) {
                escape = true;
                continue;
              }

              if ((i + 1) < input.length()) {
                String nextChar = input.substring(i + 1, i + 2);

                re = new RE("[\\*\\+]");
                if (re.isMatch(nextChar)) {
                  result += nextChar;
                  i++;
                }
              }

              if ((i + 1) < input.length()) {
                String nextChar = input.substring(i + 1, i + 2);

                re = new RE("[\\?]");
                if (re.isMatch(nextChar)) {
                  result += nextChar;
                  i++;
                }
              }

              result += ")";
              debugInfo.addSubexpressionPosition(start, i + 1);
              debugInfo.addBracketPosition(bracketStart, result
                  .length() - 1);

            }

          } else {

            re = new RE("[\\]\\}]");
            if (re.isMatch(character)) {
              if ((i + 1) < input.length()) {

                String nextChar = input.substring(i + 1, i + 2);

                if (nextChar.equals("{")) {
                  result += character + nextChar;
                  i++;
                  continue;
                }

                re = new RE("[\\+\\*]");
                if (re.isMatch(nextChar)) {
                  result += character + nextChar;
                  i++;

                  if ((i + 1) < input.length()) {
                    nextChar = input
                        .substring(i + 1, i + 2);

                    re = new RE("[\\?]");
                    if (re.isMatch(nextChar)) {
                      result += nextChar;
                      i++;
                    }
                  }
                  result += ")";
                  debugInfo.addSubexpressionPosition(start,
                      i + 1);
                  debugInfo.addBracketPosition(bracketStart,
                      result.length() - 1);

                  inBracket = false;

                } else {
                  result += character + ")";
                  debugInfo.addSubexpressionPosition(start,
                      i + 1);
                  debugInfo.addBracketPosition(bracketStart,
                      result.length() - 1);
                  inBracket = false;
                }
              }
              // If it's the last character
              else {
                result += character + ")";
                debugInfo
                    .addSubexpressionPosition(start, i + 1);
                debugInfo.addBracketPosition(bracketStart,
                    result.length() - 1);
                inBracket = false;
              }

            } else {
              result += character;
            }
          }

        }

      } else {
        // Handle pre-formatted regexp
        //..................................
        result = input;

        re = new RE("\\((.*?)\\)");

        REMatch[] matches = re.getAllMatches(convInput);

        for (int i = 0; i < matches.length; i++) {
          for (int j = 1; j <= re.getNumSubs(); j++) {
            start = matches[i].getStartIndex(j);
            end = matches[i].getEndIndex(j);
            debugInfo.addSubexpressionPosition(start, end);
            debugInfo.addBracketPosition(start, end);
          }
View Full Code Here

    public void initMatches() {
      // Get longest match
      String reg = null;
      boolean found = false;
      RE re = null;

      this.allMatches.clear();

      try {
        for (int i = bracketsInRegexp.size() - 1; i >= 0; i--) {
          SubexpressionPos pos = (SubexpressionPos) bracketsInRegexp
              .get(i);
          reg = regexp.substring(0, pos.getEnd() + 1);

          re = new RE(reg, eflags);
          if (re.getAllMatches(matchString).length > 0) {
            matchingBracketsCount = i + 1;
            found = true;

            break;
          }
        }

        if (re != null && found) {
          REMatch[] matches = re.getAllMatches(matchString);
          for (int j = 0; j < matches.length; j++) {
            this.allMatches.add(matches[j]);
          }
        }
      } catch (Exception e) {
View Full Code Here

TOP

Related Classes of gnu.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.