I have a function that accepts one input, an array, that can have X number of values. I have a string, which indicates the final format desired.
Example:
function doFormat(args) {
const format = 'Foo \\d{1,2}x\\d{2} Bar';
}
doFormat([123, 2, 3]);
Let's assume, for now, that format will only contain a regex pattern that matches numbers with \\d, and that inputs will only contain numbers.
In this specific example, I want to coerce the input args into the string Foo 12x02 Bar, as required by the format variable, because the first match of \\d{1,2} restricts it to an integer with a maximum length of 2 (therefore trimming the first input, from 123 to just 12), and the second match of \\d{2} restricts to an integer with a length of exactly 2 (therefore padding the second input, from 2 to 02). And we drop the third input of 3, because it isn't used in format.
How can I achieve this? I'm using this in a Node script run on a server, so I can use any NPM packages, if necessary.
argsinput and theformat. I can remove the example if that would help...formatbe any valid regex? The latter sounds hard and my gut tells me it's also NP-complete