Package monq.jfa

Class Regexp

java.lang.Object
monq.jfa.Regexp

public final class Regexp extends Object

Convenience class for matching regular expressions with a Dfa.

If you don't need to store values in a Dfa but only want to check if a string completely matches a regular expression, starts with or contains a match, use this class. This class can be used somewhat similar to Matcher.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a Regexp object for the given regular expression.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    tests whether this matches a prefix of s.
    int
    atStartOf(String s, int pos)
    Tests whether this matches a prefix of s starting at position pos.
    int
    tries to find this in s.
    int
    find(String s, int start)
    Tries to find this in s starting at position start.
     
    int
    Returns the number of characters matched by the most recent match call to any of matches, atStartOf or find.
    boolean
    checks if the whole input sequence can be matched.
    boolean
    matches(String s, int pos)
    checks if the whole input sequence starting at position pos can be matched.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getDfa

      public Dfa<String> getDfa()
    • matches

      public boolean matches(String s, int pos)

      checks if the whole input sequence starting at position pos can be matched.

      Returns:
      true iff the whole input sequence starting at position pos and ending at s.length() can be matched.
    • matches

      public boolean matches(String s)

      checks if the whole input sequence can be matched. This method is equivalent to a call to matches(s, 0).

    • find

      public int find(String s, int start)

      Tries to find this in s starting at position start.

      Returns:
      the position of the match within s, i.e. not relative to start. To get the length of the match, use length(). If no match can be found, -1 is returned.
    • find

      public int find(String s)

      tries to find this in s. This method is equivalent to a call to find(s, 0).

    • atStartOf

      public int atStartOf(String s, int pos)

      Tests whether this matches a prefix of s starting at position pos.

      Returns:
      the length of the match or -1.
    • atStartOf

      public int atStartOf(String s)

      tests whether this matches a prefix of s. This method is equivalent to a call to atStartOf(s, 0).

    • length

      public int length()

      Returns the number of characters matched by the most recent match call to any of matches, atStartOf or find.

      Throws:
      IllegalStateException - if the most recent application of this did not yield a match.