I am currently working on creating a regex pattern to extract the variables passed to a JavaScript constructor.
The format of the input data will always be similar to this:
app.use(express.static('public'));
The regex I have devised to remove the unnecessary parts is as follows:
(^app.use\()|(..$)
The initial section of the regex captures everything up to the first parenthesis, and then it should pass that information to another part of the expression which extracts the last 2 characters of the string.
However, I seem to be encountering an issue where the second part of the regex is being ignored. I attempted different expressions in the second segment and they worked fine, but this particular one does not.
What mistake could I possibly be making?
An example of my regex on Regex101: https://regex101.com/r/jV9eH6/3
UPDATE:
This question is distinct from How to replace all occurrences of a string in JavaScript?
I am specifically seeking assistance with a particular problem related to regex, rather than addressing how to substitute one string for another within JavaScript.