0

我正在尝试使用正则表达式来阻止所有大写句子(只有大写字母的句子),但我无法成功找到该模式。我在考虑 ^[az] 但这根本不起作用。

有什么建议吗?

4

6 回答 6

1

You can perhaps use something like this to make sure there's at least one lowercase character (note that's this is some kind of reverse logic):

^.*[a-z].*$

(Unless the function you're using uses regex against the whole pattern by default, you can drop the beginning and end of line anchors)

If you want the regex to be more strict (though I don't think that's very practical here), you can perhaps use something of the sort...

^[A-Z.,:;/() -]*[A-Z]+[A-Z.,:;/() -]*$

To allow only uppercase letters, and some potential punctuations (you can add or remove them from the character classes as you need) and spaces.

于 2013-10-07T04:48:28.400 回答
1

只需寻找[a-z]...如果匹配,您的句子就会通过。如果不是,则全部为大写字母(或标点符号)。

于 2013-10-07T15:10:01.093 回答
0

以下正则表达式

(^|\.)[[:space:]A-Z]+\.

将在行首或前面的句号之间找到仅包含大写字母和空格的任何行。

于 2013-10-07T15:00:33.007 回答
0

不能^[A-Z]+$简单地满足您的需求?如果匹配,则表示输入字符串仅包含大写字母。

RegExr上的演示。

于 2013-10-07T07:56:56.823 回答
0

这取决于您使用的正则表达式的风格,但如果您有一个支持前瞻的正则表达式,那么您可以使用以下表达式:

(?-i)^(?!(?=.*?[A-Z])(?:[A-Z]|(?i)[^a-z])*$)

它不会捕获任何内容,但如果使用的字母全部大写,则返回 false,如果使用的任何字母为小写,则返回 true。

于 2013-10-07T07:36:21.557 回答
0

您似乎想检测单词中嵌套了大写字母的句子,例如:hEllo、gOODbye、word;那是任何在小写字母之后有一个大写字母的单词,或者任何两个或多个大写字母并排的单词。

  • 小写之后的大写

    [阿兹][阿兹]

  • 两个或多个成对的大写字母

    [AZ][AZ]

将它们与交替组合在一起,

/*([a-z][A-Z]|[A-Z][A-Z])/
于 2013-10-07T15:50:57.803 回答