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.
我正在使用以下正则表达式在字符串中查找罗马数字:
^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$
如何更改它以检测除句点之外的任何特殊字符之前或之后的罗马数字?
我会试试这个表达:
^[@!#%^*()_&-]?M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})[@!#%^*()_&-]?$
[@!#%^*()_&-]?开头和结尾的表达式匹配评论中列表中的零个或一个特殊字符。
[@!#%^*()_&-]?