Python handles this immediately, even if I added two orders to the length.
J.

#!/usr/bin/python
import re
LENGTH = 20000
var1 = "x" * LENGTH + "ABC" + "y" * 10 + "#"
var2 = "x" * LENGTH + "XYZ" + "y" * 10
var3 = "x" * LENGTH + "ABC" + "y" * 10
re = re.compile('(.*)ABC.*#')
for text in [var1, var2, var3]:
        if re.match(text):
                print "true"
        else:
                print "false"LENGTH = 20000