Performance: Move regex initializations to module scope
Description:
This PR moves all regular expression initializations in index.js to the module (outer) scope, so they are only created once and reused on every function call. This improves performance, especially when the function is called frequently.
All regex patterns are now declared as constants at the top of the file No change in functionality; all tests continue to pass Motivation: Previously, regex objects were re-initialized on every function call, which could impact performance. With this change, regex objects are created once and reused.
Tests: All existing tests (npm test) pass successfully.
As requested with proposal from @punkpeye
Done with Copilot but Tests are passing.
Done with Copilot
I checked if any regex string has changed, and the IMAGE_REGEX string is different now.
The ! symbol escape has been removed. I believe it's functionally equivalent, but it has been modified.