public boolean recognizes(String txt){
  DirectedDFS dfs=new DirectedDFS(graph,0);
  Bag<Integer> pc=new Bag<Integer>();
  for (int v=0; v < graph.V(); v++)   if (dfs.marked(v))   pc.add(v);
  for (int i=0; i < txt.length(); i++) {
    if (txt.charAt(i) == '*' || txt.charAt(i) == '|' || txt.charAt(i) == '(' || txt.charAt(i) == ')')     throw new IllegalArgumentException("text contains the metacharacter '" + txt.charAt(i) + "'");
    Bag<Integer> match=new Bag<Integer>();
    for (    int v : pc) {
      if (v == m)       continue;
      if ((regexp.charAt(v) == txt.charAt(i)) || regexp.charAt(v) == '.')       match.add(v + 1);
    }
    dfs=new DirectedDFS(graph,match);
    pc=new Bag<Integer>();
    for (int v=0; v < graph.V(); v++)     if (dfs.marked(v))     pc.add(v);
    if (pc.size() == 0)     return false;
  }
  for (  int v : pc)   if (v == m)   return true;
  return false;
}

public boolean recognizes ( String txt ) { DirectedDFS dfs = new DirectedDFS ( graph , 0 ) ; Bag < Integer > pc = new Bag < Integer > ( ) ; for ( int v = 0 ; v < graph . V ( ) ; v ++ ) if ( dfs . marked ( v ) ) pc . add ( v ) ; for ( int i = 0 ; i < txt . length ( ) ; i ++ ) { if ( txt . charAt ( i ) == '*' || txt . charAt ( i ) == '|' || txt . charAt ( i ) == '(' || txt . charAt ( i ) == ')' ) throw new IllegalArgumentException ( "text contains the metacharacter '" + txt . charAt ( i ) + "'" ) ; Bag < Integer > match = new Bag < Integer > ( ) ; for ( int v : pc ) { if ( v == m ) continue ; if ( ( regexp . charAt ( v ) == txt . charAt ( i ) ) || regexp . charAt ( v ) == '.' ) match . add ( v + 1 ) ; } dfs = new DirectedDFS ( graph , match ) ; pc = new Bag < Integer > ( ) ; for ( int v = 0 ; v < graph . V ( ) ; v ++ ) if ( dfs . marked ( v ) ) pc . add ( v ) ; if ( pc . size ( ) == 0 ) return false ; } for ( int v : pc ) if ( v == m ) return true ; return false ; }
returns true if the text is matched by the regular expression .
