in reply to Re: Using constants in regexes?
in thread Using constants in regexes?

Your statements about the middle example are the only correct thing in your post. In your example /${\(TEST)}/ you state that it can't be compiled. This is false. First time this expression is executed the string form of it is compiled. Since the string form will never change, the compiled expression is retained for the life of the process. You do still incur a runtime hit of evaluating ${\TEST} each time but that is not comparable with the regex compilation cost. That recurring cost can be removed by appending the /o flag which informs the interpreter to never attempt to evaluate the string again. So /${\TEST}/o is perfectly fine and imposes no performance penalty.

Your last example uses the same logic I just described for the first example. The ${\PATTERN} string is still evaluated every time except this time you never have the option to use the /o parameter.