如何在正则表达式中选择ALLCAPS值? [英] How to Select thw ALLCAPS values in regex?

查看:94
本文介绍了如何在正则表达式中选择ALLCAPS值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是在文档中选择罗马字母条款的组合,条款可以是小写字母或大写字母,而不是混合(IiVx)



my requirement is select the combination of roman letters terms in document, that terms may be in small letters or caps letters, not be in mixed (IiVx)

i use the regex format for select the terms

regex = new Regex(@"\b([ivxlcdm]+|[IVXLCDM]+)\b");

but document contains ALLCAPS format terms they didnt select by regex , any one help to me

推荐答案

你可以尝试这个表达式

You can try this expression
(?<roman>\b[IVXLCDM]+\b)|(?<roman>\b[ivxlcdm]+\b)



它基本上是说小写字母OR(|大写字母,但不是两者。

确保关闭IgnoreCase。


It basically says, either small letters OR (|) capital letters, but not both.
Make sure you turn off IgnoreCase.


书签: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch06s09.html [ ^ ]

上面用于查找全部罗马数字。检查一下,如果失败,然后对小帽进行另一个类似的正则表达式检查,只需将前一个正则表达式中的所有字母转换为小字母。或者

Book mark this: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch06s09.html[^]
The above is for finding All-Cap Roman Numerals. Check against this, if fail, then have another similar regex check for small cap, just convert all the letters in the previous regex to small ones. Or
(ALL-CAP regex)|(small cap regex)



了解更多: 30分钟正则表达式教程 [ ^ ]


这篇关于如何在正则表达式中选择ALLCAPS值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆