See if string is a Roman numeral. - Java java.lang

Java examples for java.lang:Number

Description

See if string is a Roman numeral.

Demo Code

/*   Please see the license information at the end of this file. */
//package com.java2s;

public class Main {
    /**   Regular expression pattern matching a Roman numeral. */

    protected static String romanNumeralPattern = "^\\.{0,1}M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})"
            + "(I[XV]|V?I{0,3}|V?I{0,2}J)\\.{0,1}$";

    /**   See if string is a Roman numeral.
     */*w ww  .j  a v  a  2s  .c o  m*/
     *   @param   s   The string.
     *
     *   @return      true if string is a valid Roman numeral.
     */

    public static boolean isRomanNumeral(String s) {
        return s.toUpperCase().matches(romanNumeralPattern);
    }
}

Related Tutorials