How can I change the matching pattern at run time?

You can’t, it’s compiled into a static table when flex builds the scanner.