A method for performing a Deep Packet Inspection, DPI, the method comprising: • detecting (302; 1001) for each pattern from a pattern set a pattern offset, wherein the pattern offset either indicates that the whole data packet is to be searched for the pattern or it defines a first byte of the packet at which the pattern has to be searched in the packet, wherein the patterns of the pattern set are REGEXs, regular expressions; • creating (303; 1002) for each pattern offset indicating which part of the data packet is to be searched for the pattern in the pattern set an indexed pattern group (101-0 - 101-N), wherein the index of the indexed pattern group corresponds to the pattern offset; • adding (306; 1003) each pattern in the pattern set having the same pattern offset indicating which part of the data packet is to be searched for the pattern to the indexed pattern group having an index corresponding to the pattern offset; • adding (307; 1004) each pattern having the pattern offset indicating that the whole data packet is to be searched for the pattern to each of the indexed pattern groups; • compiling (310; 1005) each indexed pattern group into an indexed data field (203, 204), wherein each indexed data field (203, 204) is based on a corresponding Trie (203, 204), wherein the Trie (203, 204) comprises nodes, wherein each node corresponds to a character of the patterns included in the indexed pattern group; • comparing, for each indexed data field, the patterns of the Trie (203, 204) with elements of a received data packet, wherein a first element of the data packet to be compared with the patterns of the Trie (203, 204) is indicated by the index of the indexed data field (203, 204); • reporting a match if a pattern in the data packet matches a pattern in the indexed data field (203, 204). • detecting (302; 1001) for each pattern from a pattern set a pattern offset, wherein the pattern offset either indicates that the whole data packet is to be searched for the pattern or it defines a first byte of the packet at which the pattern has to be searched in the packet, wherein the patterns of the pattern set are REGEXs, regular expressions; • creating (303; 1002) for each pattern offset indicating which part of the data packet is to be searched for the pattern in the pattern set an indexed pattern group (101-0 - 101-N), wherein the index of the indexed pattern group corresponds to the pattern offset; • adding (306; 1003) each pattern in the pattern set having the same pattern offset indicating which part of the data packet is to be searched for the pattern to the indexed pattern group having an index corresponding to the pattern offset; • adding (307; 1004) each pattern having the pattern offset indicating that the whole data packet is to be searched for the pattern to each of the indexed pattern groups; • compiling (310; 1005) each indexed pattern group into an indexed data field (203, 204), wherein each indexed data field (203, 204) is based on a corresponding Trie (203, 204), wherein the Trie (203, 204) comprises nodes, wherein each node corresponds to a character of the patterns included in the indexed pattern group; • comparing, for each indexed data field, the patterns of the Trie (203, 204) with elements of a received data packet, wherein a first element of the data packet to be compared with the patterns of the Trie (203, 204) is indicated by the index of the indexed data field (203, 204); • reporting a match if a pattern in the data packet matches a pattern in the indexed data field (203, 204).