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 關注
- 366 瀏覽
添加回答
舉報