Could you tell me how to write the regular expression required like this?

recently, regular matching is required for input:
for example, input can only be 60G, 1T is preceded by a number, followed by a capacity unit;
there is a 60G/ month; the front numerical unit of 50G/ half a year is also followed by this kind of control requirement of the unit;
how should a similar regular expression be written? Thank you


/\d+[KMGT](\/(|))?/

d + any
of more than one number
[KMGT] unit (/ (month | half a year)? Optional units of time


'60G/'.match(/^\d+(G|T)(\/\W{1,2})?/g)//["60G/"]
'60G'.match(/^\d+(G|T)(\/\W{1,2})?/g)//["60G"]
'1T'.match(/^\d+(G|T)(\/\W{1,2})?/g)//

is not so perfect, for reference only


/^\d+[KMGT](?:\/(?:|?))?$/i
Menu