See if string is a Roman numeral using looser (older) definition. - Java java.lang

Java examples for java.lang:Number

Description

See if string is a Roman numeral using looser (older) definition.

Demo Code

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

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

    //   protected static String looseRomanNumeralPattern   =
    //      "^\\.{0,1}M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})" +
    //      "(I[XV]|V?I{0,4}|V?I{0,3}J)(O|M|ST|US){0,1}\\.{0,1}$"
    //      ;//from  w  ww  . j a  v  a  2 s. c o m

    protected static String looseRomanNumeralPattern = "^\\.{0,1}M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})"
            + "(I[XVU]|[UV]?I{0,4}|[UV]?I{0,3}J)(O|M|ST|US){0,1}\\.{0,1}$";

    /**   See if string is a Roman numeral using looser (older) definition.
     *
     *   @param   s   The string.
     *
     *   @return      true if string is a valid Roman numeral using
     *            looser (older) definition.
     */

    public static boolean isLooseRomanNumeral(String s) {
        return s.toUpperCase().matches(looseRomanNumeralPattern);
    }
}

Related Tutorials