So Basically I want to remove Abbreviations of length more than 2 so that lower case x.y is preserved but Upper Case X.Y.Z. is removed. Also I want to remove any words which are Upper Case and are of length>=3. Such as abc is preserved but IIT is removed.
您可以尝试以下正则表达式:
RegEx Demo
正则表达式详细信息:
\b
:单词边界(?:
:启动一个非捕获组[A-Z]{3,}\b
:匹配3个以上大写字母的单词|
:或(?:[A-Za-z]\.){2,}
:匹配字母缩写,后跟最小长度为2的点)
:非捕获组\s*
:匹配0个或多个空格你可以用
解释
(?<!\S)
左边的空白边界(?:
非捕获组(?:[A-Za-z]\.){3,}
重复3次或更多次A-Za-z,后跟一个点|
或[A-Z]{3,}
匹配3个大写字符)
关闭非捕获组(?!\S)
右边的空白边界Regex demo
相关问题 更多 >
编程相关推荐