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

前端 未结 16 2216
無奈伤痛
無奈伤痛 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

    As Jeremy and Pax pointed out above ... '^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$' should be the solution you're after ...

    The specific URL that should have been attached (IMHO) is http://thehazeltree.org/diveintopython/7.html

    Example 7.8 is the short form using {n,m}

提交回复
热议问题