[英]What does this mean in regular expressions? re.match(r“(^[cf-qs-z]+)”, any file name)?
我偶然发现了这段代码,但我不知道它匹配什么:
re.match(r"(^[cf-qs-z]+)", words)
fq
and sz
are character ranges , meaning any letter from f
to q
and from s
to z
in the alphabet, case sensitive fq
和sz
是字符范围 ,表示字母中从f
到q
以及从s
到z
的任何字母,区分大小写 c
is a literal character c
- no special meaning c
是文字字符 c
没有特殊含义 ^
defines the beginning of a string ^
定义字符串的开头 +
is a quantifier , it means "one or more" +
是一个量词 ,表示“一个或多个” In other words the expression would match 1 more characters that are c
or in f
to q
or s
to z
range at the start of a string. 换句话说,该表达式将在字符串的开头再匹配1个字符
c
或在f
到q
或s
到z
范围内的c
。
In cases like this, if you need an explanation for an existing regular expression, try pasting it to https://regex101.com , here is what it generates for this expression: https://regex101.com/r/cU0yT7/1 . 在这种情况下,如果您需要对现有正则表达式的解释,请尝试将其粘贴到https://regex101.com ,这是它为该表达式生成的内容: https : //regex101.com/r/cU0yT7/1 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.