1

这可以简化以避免重复吗?最好不要有重复的组。

这是我的正则表达式的结构化输出,具有声誉:

^(?<Version>(\d+)\.(\d+)\.(\d+))(?!.*[\.-]$)(?:(?<IsReleaseVersion>-)(?:(?:(?<RArea1>[\da-z][\.\da-z-]+)\.(?<RStep1>[\d]+)\.(?<RHash1>[\.\da-z]+)\.(?<RCiId1>\d{1,4}))|(?:(?<RArea2>[\da-z][\.\da-z-]+)\.(?<RStep2>[\d]+)\.(?<RId2>[\.\da-z]+))|(?:(?<RArea3>[\da-z][\.\da-z-]+)\.(?<RStep3>[\d]+))|(?:(?<RArea4>[\da-z][\.\da-z-]+))))?(?:(?<IsBuildVersion>\+)(?:(?:(?<BArea1>[\da-z][\.\da-z-]+)\.(?<BStep1>[\d]+)\.(?<BId2>[\.\da-z]+)\.(?<BCiId2>\d{1,4}))|(?:(?<BArea2>[\da-z][\.\da-z-]+)\.(?<BStep2>[\d]+)\.(?<BId2>[\.\da-z]+))|(?:(?<BArea3>[\da-z][\.\da-z-]+)\.(?<BStep3>[\d]+))|(?:(?<BArea4>[\da-z][\.\da-z-]+))))?$

这是输入文本:

<Version>: (A)=1.0.1 (B)=1.0.1 (C)=1.0.1 (D)=1.0.1 (E)=1.0.1 (F)=1.0.1 (1): (A)=1 (B)=1 (C)=1 (D)=1 (E)=1 (F)=1 (2): (A)=0 (B)=0 (C)=0 (D)=0 (E)=0 (F)=0 (3): (A)=1 (B)=1 (C)=1 (D)=1 (E)=1 (F)=1 <IsReleaseVersion>: (A)=null (B)=null (C)=null (D)=null (E)=null (F)=- <IsBuildVersion>: (A)=+ (B)=+ (C)=+ (D)=+ (E)=null (F)=null <Area>: (A)=beta (B)=beta (C)=beta (D)=beta (E)=null (F)=beta <Step>: (A)=1 (B)=1 (C)=1 (D)=null (E)=null (F)=1 <Id>: (A)=abcd1234 (B)=abcd1234 (C)=null (D)=null (E)=null (F)=abcd1234 <CiId>: (A)=0001 (B)=null (C)=null (D)=null (E)=null (F)=null 

我希望有人能帮助我!

4

1 回答 1

1

天哪,你搞得一团糟:)我只关注这部分:

((?:(?:(?<RArea1>[\da-z][\.\da-z-]+)\.(?<RStep1>[\d]+)\.(?<RHash1>[\.\da-z]+)\.(?<RCiId1>\d{1,4}))|
(?:(?<RArea2>[\da-z][\.\da-z-]+)\.(?<RStep2>[\d]+)\.(?<RId2>[\.\da-z]+))|
(?:(?<RArea3>[\da-z][\.\da-z-]+)\.(?<RStep3>[\d]+))|
(?:(?<RArea4>[\da-z][\.\da-z-]+)))

这可以重写为:

(?:(?<Area>[\da-z]+)(?:\.(?<Step>[\d]+)(?:\.(?<Hash>[\da-z]+)(?:\.(?<CiId>\d{1,4}))?)?)?)

简单地嵌套你的条件。

看到它在行动

于 2013-03-11T23:51:35.677 回答