package it.matjaz.numerus.core;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Matjaž <a href="mailto:dev@matjaz.it">dev@matjaz.it</a>
 * <a href="http://matjaz.it">www.matjaz.it</a>
 */
public class RomanNumeral {

    private String symbols;
    public final String NON_ROMAN_CHARS_REGEX = "[^MDCLXVI]";

    public RomanNumeral() {
        this.symbols = "";
    }

    public String getSymbols() {
        return symbols;
    }

    public void setSymbols(String symbols) {
        String cleanSymbols = cleanSymbolsString(symbols);
        checkRomanSyntax(cleanSymbols);
        this.symbols = cleanSymbols;
    }

    private static String cleanSymbolsString(String symbols) {
        return symbols.replaceAll("\\s+", "").toUpperCase();
    }

    // from http://stackoverflow.com/questions/5705111/how-to-get-all-substring-for-a-given-regex
    private static String getAllMatches(String textToParse, String regex) {
        StringBuilder matches = new StringBuilder();
        Matcher matcher = Pattern.compile(regex).matcher(textToParse);
        while (matcher.find()) {
            matches.append(matcher.group());
        }
        return matches.toString();
    }

    private void checkRomanSyntax(String symbols) {
        if (symbols.isEmpty()) {
            throw new NumberFormatException("Empty roman numeral.");
        }
        if (symbols.length() >= 20) {
            throw new NumberFormatException("Impossibly long roman numeral.");
        }
        String matches;
        matches = getAllMatches(symbols, NON_ROMAN_CHARS_REGEX);
        if (!matches.isEmpty()) {
            throw new NumberFormatException("Non roman characters: " + matches);
        }
    }

}

@@ -275,67 +275,767 @@
 ls;%0A
-    public final String NON_ROMAN_CHARS_REGEX = %22%5B%5EMDCLXVI%5D
+%0A    /**%0A     * A big regex matching all syntactically correct roman numerals.%0A     *%0A     * Contains all possible cases of roman numerals. If a string does not match%0A     * this regex, then is not a roman numeral.%0A     */%0A    public final String CORRECT_ROMAN_SYNTAX_REGEX = %22%5E(M%7B0,3%7D)(CM%7CCD%7CD?C%7B0,3%7D)(XC%7CXL%7CL?X%7B0,3%7D)(IX%7CIV%7CV?I%7B0,3%7D)$%22;%0A%0A    /**%0A     * Non roman characters.%0A     */%0A    public final String NON_ROMAN_CHARS_REGEX = %22%5B%5EMDCLXVI%5D%22;%0A%0A    /**%0A     * Four consecutive characters M or C or X or I.%0A     */%0A    private final String FOUR_CONSECUTIVE_TEN_LIKE_CHARS_REGEX = %22(MMMM%7CCCCC%7CXXXX%7CIIII)%22;%0A%0A    /**%0A     * Two non necessary consecutive characters D or L or V.%0A     */%0A    private final String TWO_SAME_FIVE_LIKE_CHARS_REGEX = %22(D.*D%7CL.*L%7CV.*V)
 %22;%0A%0A

Add some regexes to RomanNumeral and their basic JavaDoc.