core: fix memory leak in regex matching when evaluating expression