Regex 正则表达式只允许某些字符大写字母A-Z';-和空间
我不熟悉正则表达式。我需要在正则表达式中验证字符串-Regex 正则表达式只允许某些字符大写字母A-Z';-和空间,regex,Regex,我不熟悉正则表达式。我需要在正则表达式中验证字符串- Capital letters A-Z ' - and space 我不熟悉这个正则表达式的概念- and tried [A-Z,',-]* -> Any character in this class [A-Z,',/]. any number of repeatitions. 我试图验证,但我不是很有信心,因为我还没有指定这个正则表达式甚至可以验证空格。。 如果有人能给我一些建议或提供一些信息,我将不胜感激。如果
Capital letters A-Z ' - and space
我不熟悉这个正则表达式的概念-
and tried [A-Z,',-]* -> Any character in this class [A-Z,',/]. any number of repeatitions.
我试图验证,但我不是很有信心,因为我还没有指定这个正则表达式甚至可以验证空格。。
如果有人能给我一些建议或提供一些信息,我将不胜感激。如果我遗漏了一些东西,你不能在[]中用逗号分隔字符,所以你应该使用[a-Z'\-]*
您需要使用\,因为“-”在[]中有特殊含义。在[]中不能用逗号分隔字符,所以您应该使用[a-Z'\-]*
您需要使用\-因为“-”在[]中有特殊含义。您需要避开特殊字符:“和”-
[A-Z\-\']*
应该可以用。你需要摆脱特殊字符:'and'-
[A-Z\-\']*
应该可以工作。字符类中不需要逗号。因此,以下内容适用于您:
[A-Z' -]+
这意味着:
A-Z - Capital letters from A-Z (Range)
' - Single Quote
" " - Space (double quotes only to show you space)
- - Hyphen (must appear as 1st or last in character class in order to avoid escaping
[A-Z' -]+ - Match 1 or more of the above allowed characters
字符类中不需要逗号。因此,以下内容适用于您:
[A-Z' -]+
这意味着:
A-Z - Capital letters from A-Z (Range)
' - Single Quote
" " - Space (double quotes only to show you space)
- - Hyphen (must appear as 1st or last in character class in order to avoid escaping
[A-Z' -]+ - Match 1 or more of the above allowed characters
对于大写字母A-Z'-和空格 您可以使用
[A-Z\s\'\-]
\s
代表空格,\
代表'
,-
代表-
,大写字母A-Z'-和空格不需要逗号
您可以使用[A-Z\s\'\-]
\s
表示空格,\
表示\
,\-
表示-
,不需要逗号