Regular Expressions 101

Community Patterns

Community Library Entry

-2

Regular Expression
ECMAScript (JavaScript)

/
^(?!$)M{0,2}(?:M(?=CM(?:XC)?(?:IX)?$))?(?:C(?=M[^CD]*(?:XC)?[^CD]*$))?M?(?:C(?=D[^C]*(?:XC)?[^C]*$))?D?C{0,2}(?:C(?=XC(?:IX)?$))?(?:X(?=C[^X]*(?:IX)?[^X]*$)(?!.*L))?C?(?:X(?=L[^X]*(?:IX)?[^X]*$))?L?X{0,2}(?:X(?=IX$))?(?:I(?=[XV]$))?X?V?I{0,3}$
/

Description

This regex matches roman numbers from 1 (I) to 3999 (MMMCMXCIX)

Submitted by Nicolò Ribaudo - 9 years ago