Hi. I am making a Discord chat bot and I need to parse a time duration string in this format:
Code:
1y2m3w4d5h6min7s
Exactly in this order. The seconds modifier does not need to be used (default time unit), and the specified time can omit any of the unit counts (including the unit), which renders that unit zero and is not used.

I have following structure for the parsed time prepared:
Code:
let duration = {
    years: 0,
    months: 0,
    weeks: 0,
    days: 0,
    hours: 0,
    minutes: 0,
    seconds: 0
};
and the constants to mupltiply the specified time to milliseconds:
Code:
module.exports.time_constants = {
    year: 3.1556926e10,
    month: 2.62974383e9,
    week: 604800000,
    day: 86400000,
    hour: 3600000,
    minute: 60000,
    second: 1000
};
The question is - do you know the most efficient way to parse the given time string? I'd like to avoid using ANTLR, because I don't quite understand how to use it and can't find any simplified information on how to use it, what each part of the generated code actually does and how to use that for own bussiness.

But better be safe than sorry, so I also prepared a gramar file for the time specification:
Code:
grammar time;

fragment INT:
    [1-9] [0-9]*
    ;

fragment Y: [yY];
fragment M: [mM];
fragment W: [wW];
fragment D: [dD];
fragment H: [hH];
fragment I: [iI];
fragment N: [nN];
fragment S: [sS];

time:
    years? months? weeks? days? hours? minutes? seconds?
    // #y#m#w#d#h#min#s
    ;

years: (INT Y)?;
months: (INT M)?;
weeks: (INT W)?;
days: (INT D)?;
hours: (INT H)?;
minutes: (INT M I N)?;
seconds: (INT S?)?;
The issue with it is that "m" also matches "min" when I use regex. Please, will someone help me?