I need a regex expression which should satisfy the following rules :
我需要一个regex表达式,它应该满足以下规则:
- Must be between 8-32 characters long
- 必须在8-32个字符之间?
- Must begin with a letter
- 必须从一封信开始?
- Must not contain any spaces
- 不能包含任何空格?
- Must not contain any special characters
- 不能包含任何特殊字符?
I tried my own expression with the help of google like ^([a-zA-Z][a-zA-Z0-9]{8-32}[<>%\*])$
but this is throwing me an error like "Can't do regex matching, reason: Can't open pattern U_REGEX_BAD_INTERVAL "
我试着自己的表情在谷歌的帮助下像^([a-zA-Z][a-zA-Z0-9]{ 8-32 } < > % \[*])但这是美元扔我一个错误像“做不到正则表达式匹配,原因:打不开模式U_REGEX_BAD_INTERVAL”
Please help me. Thanks in advance.
请帮助我。提前谢谢。
1 个解决方案
#1
5
How about:
如何:
^[A-Za-z][A-Za-z0-9]{7,31}$
This only allows characters A-Z, a-z, and the numbers 0-9, which automatically excludes spaces and special characters.
这只允许字符A-Z、A-Z和数字0-9,自动排除空格和特殊字符。
The explanation:
解释:
-
^[A-Za-z]
means that it must start with a letter, either A-Z or a-z. The^
symbol indicates the start. - ^[A-Za-z]意味着它必须从字母开始,a - z、a - z。^符号表示开始。
-
[A-Za-z0-9]{7,31}$
means that after the first rule is satisfied, there must be between 7 and 31 characters that are numbers or letters, after which we must reach the end; the$
indicates the end. If you have other characters you want to allow, you can add them to the first set of brackets, just don't forget to escape anything that needs it (such as*
). - [A-Za-z0-9]{7,31}$意味着在第一个规则得到满足之后,必须有7到31个字符,这些字符是数字或字母,然后我们必须达到目的;$表示结束。如果您想要允许其他字符,您可以将它们添加到第一组括号中,只是不要忘记避开需要它的任何东西(比如*)。
Also notice that I used {7,31} to indicate 7 to 31 repetitions with a comma, not a dash as you have in your sample code. This is the reason you get the U_REGEX_BAD_INTERVAL
error: intervals are expressed with {}
and a comma.
还要注意,我使用了{7,31},以逗号表示7到31的重复,而不是在示例代码中显示的。这就是您获得U_REGEX_BAD_INTERVAL错误的原因:间隔用{}和逗号表示。
#1
5
How about:
如何:
^[A-Za-z][A-Za-z0-9]{7,31}$
This only allows characters A-Z, a-z, and the numbers 0-9, which automatically excludes spaces and special characters.
这只允许字符A-Z、A-Z和数字0-9,自动排除空格和特殊字符。
The explanation:
解释:
-
^[A-Za-z]
means that it must start with a letter, either A-Z or a-z. The^
symbol indicates the start. - ^[A-Za-z]意味着它必须从字母开始,a - z、a - z。^符号表示开始。
-
[A-Za-z0-9]{7,31}$
means that after the first rule is satisfied, there must be between 7 and 31 characters that are numbers or letters, after which we must reach the end; the$
indicates the end. If you have other characters you want to allow, you can add them to the first set of brackets, just don't forget to escape anything that needs it (such as*
). - [A-Za-z0-9]{7,31}$意味着在第一个规则得到满足之后,必须有7到31个字符,这些字符是数字或字母,然后我们必须达到目的;$表示结束。如果您想要允许其他字符,您可以将它们添加到第一组括号中,只是不要忘记避开需要它的任何东西(比如*)。
Also notice that I used {7,31} to indicate 7 to 31 repetitions with a comma, not a dash as you have in your sample code. This is the reason you get the U_REGEX_BAD_INTERVAL
error: intervals are expressed with {}
and a comma.
还要注意,我使用了{7,31},以逗号表示7到31的重复,而不是在示例代码中显示的。这就是您获得U_REGEX_BAD_INTERVAL错误的原因:间隔用{}和逗号表示。