1

I have been trying to figure out a REGEX used by TeamCity in the File Content Replacer build feature and understand the majority of what it does to get the build number from the AssemblyVersion string in my GlobalAssemblyInfo. However, the replace string is leaving me somewhat mistified.

The multiline regex pattern is:

(^\s*\[\s*assembly\s*:\s*((System\s*\.)?\s*Reflection\s*\.)?\s*AssemblyVersion(Attribute)?\s*\(\s*@?\")(([0-9\*])+\.?)+(\"\s*\)\s*\])

the replace string is:

$1\%build.number%$7

a full example is here: RegexStorm Tester

Essentially, what I get is a group, with "4 captures" (see $5 on the link), and I am trying to access the captures individually so that my replace string would be more like:

$1$5[0].$5[1].$5[2]\%build.number%$7  

Meaning that the resulting AssemblyVersion then becomes 1.0.0.%build.number%.

Does anyone know if this is possible? Or do I have to use a different pattern in order to get this level of granularity?

Chris Watts
  • 822
  • 1
  • 9
  • 27
  • You cannot access the capture collection with the backreferences inside a replacement pattern. The approach should look like [`(\[assembly:\s*AssemblyVersion\(")\d+(?:\.\d+){3}("\)\s*])`](http://regexstorm.net/tester?p=(%5c%5bassembly%3a%5cs*AssemblyVersion%5c(%22)%5cd%2b(%3f%3a%5c.%5cd%2b)%7b3%7d(%22%5c)%5cs*%5d)&i=%5bassembly%3a+AssemblyVersion(%221.0.0.0%22)%5d%0d%0a&r=%241%5c%25build.number%25%242&o=m). – Wiktor Stribiżew Mar 16 '16 at 10:53
  • @WiktorStribiżew Thanks for the prompt reply! So I will need a new pattern.. Any ideas for that? I'm not exactly "familiar" with regexs, we like to keep a distance between us... – Chris Watts Mar 16 '16 at 10:55
  • I do not know how to best adjust your existing regex, I suggest a new one. Please check the one above. – Wiktor Stribiżew Mar 16 '16 at 10:57
  • @WiktorStribiżew thats a much tidier regex than the one TeamCity was using! I shall try to extract the number info now, thanks for that! – Chris Watts Mar 16 '16 at 10:59
  • Heavily bracketed modification of yours...: `(\[assembly:\s*AssemblyVersion\(")((\d)(((?:\.\d+))((?:\.\d+))((?:\.\d+))))("\)\s*])` and the replace pattern would be changed therefore to: `$1$3$5$6.\%build.number%$+` – Chris Watts Mar 16 '16 at 11:02

0 Answers0