Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex Explanation required

My Regex:

\d{0,2}\.?\d{0,3}r?em

string to match:

12123rem

Why is it matching 5 digits?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want it to match the following pattern only:
12em or 12 rem or 12.345em or 12.345rem

up to 3 decimal places only.

>Solution :

Try this one:

^\d{0,2}(\.\d{1,3})?\s?r?em$

Here is a demo

  • ^ – assures we are at the begining of the string
  • ^\d{0,2} zero up to two decimals after begining of string
  • (\.\d{1,3}) optional group of 1 up to 3 digits with . in front
  • \s? optional whitespace character
  • r? optional r character
  • em mandatory em
  • $ end of the string
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading