Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一个字符串 a = I,II,III,IV,V,VI,VII,VIII
如何使用模式来检查我的输入字符串是否与这些罗马数字中的任何一个匹配?
或者有没有更简单的方法可以做到这一点?
String pattern="^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"; String input="VIII"; if(input.matches(pattern)){ System.out.println("true"); }else{ System.out.println("false"); }
如何仅将有效的罗马数字与正则表达式匹配?