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

前端 未结 16 2248
無奈伤痛
無奈伤痛 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条回答
  •  旧时难觅i
    2020-11-22 03:23

    Actually, your premise is flawed. 990 IS "XM", as well as "CMXC".

    The Romans were far less concerned about the "rules" than your third grade teacher. As long as it added up, it was OK. Hence "IIII" was just as good as "IV" for 4. And "IIM" was completely cool for 998.

    (If you have trouble dealing with that... Remember English spellings were not formalized until the 1700s. Until then, as long as the reader could figure it out, it was good enough).

提交回复
热议问题