How do you match only valid roman numerals with a regular expression?

前端 未结 16 2207
無奈伤痛
無奈伤痛 2020-11-22 02:44

Thinking about my other problem, i decided I can\'t even create a regular expression that will match roman numerals (let alone a context-free grammar that will generate them

16条回答
  •  隐瞒了意图╮
    2020-11-22 03:23

    Steven Levithan uses this regex in his post which validates roman numerals prior to "deromanizing" the value:

    /^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/
    

提交回复
热议问题