Class Regex

java.lang.Object
it.tugamer89.autogex.regex.Regex

public class Regex extends Object
Facade class representing a compiled Regular Expression. Under the hood, it parses the regex, builds an ENFA, converts it to a DFA, and minimizes it.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Regex(String pattern)
    Compiles the given regular expression into a highly optimized Minimal DFA.
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves the underlying compiled and minimized DFA.
    Retrieves the original regular expression pattern.
    boolean
    matches(String input)
    Checks if the input string perfectly matches the regular expression.
    Exports the compiled minimal DFA to the Graphviz DOT language format.
    Exports the compiled minimal DFA to the Mermaid.js stateDiagram-v2 format.

    Methods inherited from class Object

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

    • Regex

      public Regex(String pattern)
      Compiles the given regular expression into a highly optimized Minimal DFA.
      Parameters:
      pattern - The regular expression string (e.g., "(a|b)*abb").
      Throws:
      IllegalArgumentException - If the regex syntax is invalid.
  • Method Details

    • matches

      public boolean matches(String input)
      Checks if the input string perfectly matches the regular expression.
      Parameters:
      input - The string to test.
      Returns:
      True if the string is accepted by the underlying automaton, false otherwise.
    • toDotGraph

      public String toDotGraph()
      Exports the compiled minimal DFA to the Graphviz DOT language format. This string can be rendered using Graphviz tools or online viewers.
      Returns:
      The DOT graph representation.
    • toMermaidGraph

      public String toMermaidGraph()
      Exports the compiled minimal DFA to the Mermaid.js stateDiagram-v2 format. This string can be natively rendered in GitHub Markdown without external viewers.
      Returns:
      The Mermaid.js graph representation.
    • getAutomaton

      public DFA getAutomaton()
      Retrieves the underlying compiled and minimized DFA.
      Returns:
      The minimal DFA.
    • getPattern

      public String getPattern()
      Retrieves the original regular expression pattern.
      Returns:
      The pattern string.