我是python正则表达式的新手,不知道是否有人能帮我解释一下这意味着什么(我在这里也会说明我认为每一位的含义)。在
谢谢!在
RegExp:
r'(^.*def\W*)(\w+)\W*\((.*)\):'
r'...' = python definition of regular expression within the ''
(...) = a regex term
(^. = match the beginning of any character
*def\W* = ???
(\w+) = match any of [a, z] 1 or more times
\W*\ = ? i think its the same as the line above this but from 0+ more times instead of 1 but since it matches the def\W line above (which i dont really know the meaning of) i'm not sure.
((.*)\): = match any additional character within brackets ()
谢谢!在
匹配Python function signature的尝试似乎失败了:
^{pr2}$re.DEBUG
标志导致输出:more
r''
语法与正则表达式无关(或者至少,不是直接的)。r
代表raw
,它只是Python的一个指示符,表示不应在字符串上执行字符串插值。在这通常与正则表达式一起使用,这样您就不必转义反斜杠(
\
)字符,否则正常的字符串插值机制会吃掉这些字符。在我不知道“任何角色的开头”是什么意思。
^
字符与行首匹配。在def
与字符def
匹配。对于\W
,请看一下描述正则表达式语言的pydoc re
。在同上。在
除了以上所述,你的解释基本上是正确的。在
PS:我喜欢你为理解regex所做的努力。它会很好地为你服务,比人们问
r'(^.*def\W*)(\w+)\W*\((.*)\):'
是什么意思要好得多。相关问题 更多 >
编程相关推荐