非连续大写单词的正则表达式 [英] Regex for non-consecutive upper-case words

查看:66
本文介绍了非连续大写单词的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是给您的正则表达式向导.

这是在 Notepad++ 中使用的,即直接输入到搜索和替换对话框中.

This is for use within Notepad++, i.e. it is entered directly into the search and replace dialog.

我需要匹配并突出显示嵌套在字符串中的两个或多个字符的大写字母的孤立单词,但大写单词不能连续,它们必须始终被小写单词(或小写名词与第一个字母大写)或位于句子的开头或结尾,后面或前面是小写单词(或第一个字母大写的单词.

I need to match and highlight isolated words of capital letters of two or more characters that are nested in a string, but the capitalised words must not be consecutive, they must always be surrounded by lower case words ( or lower case nouns with first letter capitalised) or be at the start or end of a sentence followed or preceded by lower case word ( or again a word with the first letter capitalised.

即.

给定字符串这是一个包含一些大写单词的句子.

我需要匹配WITH"而不是WORDS"或IN",因为 WORDS 后面是另一个大写的单词,而 IN 前面是相同的.

I need to match the "WITH" but not "WORDS" or "IN" because WORDS is followed by another capitalised word and IN is preceded by the same.

应该假设字符串是多行的.

The string should be assumed to be multi-line.

我尝试过前瞻但失败了

任何帮助将不胜感激!

:-) 谢谢

推荐答案

你应该检查周围的字符是否有负前瞻和负后视:

You should check for surrounding characters with negative lookahead and negative lookbehind:

(?<![A-Z]\s)\b[A-Z]+\b(?!\s[A-Z])

现场演示

Notepad++ v6.5.1 &也适用于多行目的

这篇关于非连续大写单词的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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