Regular Expressions 101

Community Patterns

Community Library Entry

4

Regular Expression
PCRE (PHP <7.3)

/
^(M{0,3})(C(?:D|M)|D?C{0,3})(X(?:L|C)|L?X{0,3})(I(?:V|X)|V?I{0,3})$
/

Description

Detects valid Roman numerals (up to 3999), and splits into 4 capture groups: thousands, hundreds, tens, and units.

Submitted by Terence Linnell - 9 years ago