1. A computer-implemented method for implementing regular expression matching using ternary content-addressable memory devices, comprising: receiving a set of regular expressions that specify characters to be extracted from data packets; constructing a deterministic finite automaton from the set of regular expressions; building a state transition table for each node of the deterministic finite automaton, the table having an input field having a fixed number of bits for encoding characters to be extracted from data packets, by constructing a space reduction graph from the deterministic finite automaton, where vertices of the graph represent a distinct state of the automaton and weight assigned to each edge of the graph is a number of common transitions between two connected states; trimming away edges in the graph having a weight below a predefined threshold; computing a deferment forest by finding a maximum weight spanning forest for the space reduction graph; and assigning identifiers of source states and destination states for states of the deferment forest; combining the state transition tables into a single lookup table; instantiating the lookup table in a ternary content-addressable memory device, wherein assigning identifiers further comprises constructing an assignment tree by adding a virtual root node whose children are root nodes of all deferment trees comprising the deferment forest; assigning nonzero binary identifiers to each node in the assignment tree such that all siblings have the same identifier; setting source state identifiers for each node in the assignment tree such that a source state identifier of a given node is set to a concatenation of the binary identifiers assigned to the given node and its parent nodes; identifying longest source state identifier from amongst the nodes in the assignment tree and padding remaining source state identifiers with trailing wildcard bits; and setting destination state identifiers for each node in the assignment tree such that a destination state identifier of a given node is set to corresponding source state identifier for the given node with trailing wildcard bits replaced by zeros.