[英]perl regex - pattern matching
谁能解释下面正在做什么?
$name=~m,common/([^/]+)/run.*/([^/]+)/([^/]+)$,;
common
, run
and /
are match themselves. common
, run
和/
是匹配自己的。()
captures. ()
捕获。[^/]+
matches 1 or more characters that aren't /
. [^/]+
匹配 1 个或多个不是/
字符。.*
matches 0 or more characters that aren't Line Feeds. .*
匹配 0 个或多个不是换行符的字符。 [1] [1]$
is equivalent to ( \\n?\\z
). $
等价于 ( \\n?\\z
)。 [2] [2]\\n
optionally matches a Line Feed. \\n
可选地匹配换行符。\\z
matches the end of the string. \\z
匹配字符串的结尾。I think it's trying to match a path of one or both of the following forms:我认为它试图匹配以下一种或两种形式的路径:
.../common/ XXX /runYYY/ XXX / XXX
common/ XXX /runYYY/ XXX / XXX
Where在哪里
XXX
is a sequence of at least one character that doesn't contain /
. XXX
是至少一个不包含/
字符的序列。YYY
is a sequence of any number of characters (incl zero) that doesn't contain /
. YYY
是不包含/
的任意数量字符(包括零)的序列。It matches more than that, however.然而,它比这更匹配。
uncommon/ XXX /runYYY/ XXX / XXX
它匹配uncommon/ XXX /runYYY/ XXX / XXX
common/ XXX /runYYY/XXX/XXX/XXX/XXX/ XXX / XXX
它匹配common/ XXX /runYYY/XXX/XXX/XXX/XXX/ XXX / XXX
The parts in bold are captured (available to the caller).粗体部分被捕获(可供调用者使用)。
s
flag isn't used.当不使用s
标志时。m
flag isn't used.当不使用m
标志时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.