简体   繁体   English

正则表达式是什么意思? re.match(r“(^ [cf-qs-z] +)”,任何文件名)?

[英]What does this mean in regular expressions? re.match(r“(^[cf-qs-z]+)”, any file name)?

我偶然发现了这段代码,但我不知道它匹配什么:

re.match(r"(^[cf-qs-z]+)", words)
  • The fq and sz are character ranges , meaning any letter from f to q and from s to z in the alphabet, case sensitive fqsz字符范围 ,表示字母中从fq以及从sz的任何字母,区分大小写
  • 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" +是一个量词 ,表示“一个或多个”
  • parenthesis define a capturing group 括号定义捕获组

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或在fqsz范围内的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM