理解正则表达式\?[A-Z] {2} [a-z] {2} [0-9] {2}!

时间:2022-10-29 21:15:16

I am little confused with following regular expression in python.I understand [A-Z]{2}[a-z]{2}[0-9]{2} part of it,but could not understand what /? and trailing ! mean.

我对python中的正则表达式感到困惑。我理解[A-Z] {2} [a-z] {2} [0-9] {2}的一部分,但是无法理解什么/?和尾随!意思。

\?[A-Z]{2}[a-z]{2}[0-9]{2}!

Can someone give me valid examples.Also ,does the regular expression interpretation vary according to language?(java,python etc)

有人可以给我有效的例子。还有,正则表达式解释是否因语言而异?(java,python等)

2 个解决方案

#1


1  

\? matches a question mark
[A-Z]{2} matches two capital letters following question mark
[a-z]{2} matches two small letters following the above pattern
[0-9]{2} matches two digits following above pattern
! matches an exclamation mark following above pattern

So: \?[A-Z]{2}[a-z]{2}[0-9]{2}! tested against:

所以:\?[A-Z] {2} [a-z] {2} [0-9] {2}!测试:

?AZay06!
?AZay0pp
?AZay97pp!

First of the above strings will match.

上面的第一个字符串将匹配。

I learnt regex at http://www.regexone.com/ . In my experience, interpretations of regular expressions do not vary, but the procedure to use them with delimiters does change sometimes language to language.

我在http://www.regexone.com/上学习了正则表达式。根据我的经验,正则表达式的解释不会有所不同,但将它们与分隔符一起使用的过程确实会将语言更改为语言。

#2


0  

The \? is a literal question mark. The backslash escapes the metacharacter, making it a literal. The ! is a literal exclamation point.

\?是一个字面问号。反斜杠逃脱了元字符,使其成为文字。的!是一个字面上的感叹号。

Different engines support different features, but all of them support a minimum set.

不同的引擎支持不同的功能,但它们都支持最小的设置。

#1


1  

\? matches a question mark
[A-Z]{2} matches two capital letters following question mark
[a-z]{2} matches two small letters following the above pattern
[0-9]{2} matches two digits following above pattern
! matches an exclamation mark following above pattern

So: \?[A-Z]{2}[a-z]{2}[0-9]{2}! tested against:

所以:\?[A-Z] {2} [a-z] {2} [0-9] {2}!测试:

?AZay06!
?AZay0pp
?AZay97pp!

First of the above strings will match.

上面的第一个字符串将匹配。

I learnt regex at http://www.regexone.com/ . In my experience, interpretations of regular expressions do not vary, but the procedure to use them with delimiters does change sometimes language to language.

我在http://www.regexone.com/上学习了正则表达式。根据我的经验,正则表达式的解释不会有所不同,但将它们与分隔符一起使用的过程确实会将语言更改为语言。

#2


0  

The \? is a literal question mark. The backslash escapes the metacharacter, making it a literal. The ! is a literal exclamation point.

\?是一个字面问号。反斜杠逃脱了元字符,使其成为文字。的!是一个字面上的感叹号。

Different engines support different features, but all of them support a minimum set.

不同的引擎支持不同的功能,但它们都支持最小的设置。