So, I've been trying to write out a regular expression for something like a resistance value, which contains a certain amount of digits and at most one letter, but is always a certain amount of characters total (let's use the example of a four-character resistance code).
First I could do '\d*[RKM]\d*'
but that would allow something like 'R'
.
Also, I could do something like '[\dRKM]{4}'
, but this will allow things like 'RRR4'
which is not a value that I would want.
'\d{1,4}[Rr]\d{0,3} | ([RKM]\d{3}) | (\d{4})'
, though more specific, would still allow '1234R567'
which is not four characters.
So basically, is there a more compact way of writing '[RKM]\d\d\d | \d[RKM]\d\d | \d\d[RKM]\d | \d\d\d[RKM] | \d\d\d\d'
?