B
B
Bla Bla2021-02-10 22:23:49
Node.js
Bla Bla, 2021-02-10 22:23:49

How to use regex here?

It is necessary that the first parameter in the useInput function be minutes and the second second, if input can be: "1 2" (two digits - minutes seconds), " 1" (just a digit - minutes), " 1 minutes 2", "2 seconds 1 ".
// NOT required seconds = sec = second = s; minutes = minute = min = m; That is, instead of "1 minutes" you can write "1 min"

const input = "   2   seconds   1   minutes   "
       const regexTimer = new RegExp(/([0-9]+)\s*minutes?|([0-9]+)\s*seconds?/, 'g')

       useInput(input.replace(regexTimer, '$1$2')).split(' ')); // 1 параметр минуты, второй - секунды
       
       function useInput(minutes, seconds){...};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question