3 回答
TA贡献1757条经验 获得超7个赞
TA贡献1770条经验 获得超3个赞
TA贡献1812条经验 获得超5个赞
您可以在不回溯的情况下满足指定的规则(当前接受的答案就是这样)。指定的规则是(为了清楚起见重新措辞):文件名必须满足以下条件:
它不得包含多个空格字符的序列。
逗号后面必须有一个空格字符。
文件名词干可以有一个 3 位数的后缀。
文件扩展名必须由 3 个字母组成。
为此:
^(?<prefix>[^, ]+(,? [^, ]+)*)(?<suffix>\d\d\d)?(?<extension>.\p{L}\p{L}\p{L})$
会成功的,没有花哨的前瞻,没有回溯。分解成碎片,你会得到:
^ # * match start-of-text, followed by
(?<prefix> # * a named group, consisting of
[^,\x20]+ # * 1 or more characters other than comma or space, followed by
( # * a group, consisting of
,? # * an optional comma, followed by
\x20 # * a single space character, followed by
[^,\x20]+ # * 1 or more characters other than comma or space
)* # with the whole group repeated zero or more times
) # followed by
(?<suffix> # * an optional named group (the suffix), consisting of
\d\d\d # * 3 decimal digits
)? # followed by
(?<extension> # * a mandatory named group (the filename extension), consisting of
.\p{L}\p{L}\p{L} # * 3 letters.
) # followed by
$ # end-of-text
- 3 回答
- 0 关注
- 268 浏览
添加回答
举报