我想驗證一個Excel公式的風格,具有以下的正則表達式:驗證和分組Excel公式格式
=SUM\(((?:\w+\d+)(?::\w+\d+)?)((?:,\w+\d+)(?::\w+\d+)?)*\)
在這個來源:
應該通過
=SUM(A1,A11:A212,A12:A56,A342:A12,A3)
=SUM(A11:A12,A12:a12,A34:A3)
=SUM(A1,A2,A3)
=SUM(A1)
應失敗
=SUM(A11:A212:A2,A12:A56,A4,A342:A12)
我有驗證部分工作,但我無法弄清楚如何將每個逗號分組值。他們應該是:
我多麼希望他們進行分組:
=SUM(A1,A11:A12,A12:A56,A3) // Groups: $1 = A1 $2 = A11:A12 $3 = A12:A56 $4 = A3
=SUM(A11:A12,A10:A12,A34:A3) // Groups: $1 = A11:A12 $2 = A10:A12 $3 = A34:A3
=SUM(A1,A2,A3) //Groups: $1 = A1 $2 = A2 $3 = A3
=SUM(A1) //Groups: $1 = A1
如何,他們目前正在分組:
=SUM(A1,A11:A12,A12:A56,A3) // Groups: $1 = A1 $2 = A3
=SUM(A11:A12,A10:A12,A34:A3) // Groups: $1 = A11:A12 $2 = A34:A3
=SUM(A1,A2,A3) //Groups: $1 = A1 $2 = A3
=SUM(A1) //Groups: $1 = A1
通知,其分組的第一個和最後。我對REGEX很新,所以如果我在這裏做了一件很糟糕的事情,請指出我的方向。謝謝!