Problem
I am writing a script that automates the Version Control for a series of projects. What I am trying to achieve is to store the current value of the AssemblyVersion
found within the AssemblyInfo.cs
file into a variable.
E.G.: The line is [assembly: AssemblyVersion("1.0.0.0")]
and I want to extract/store whatever value is between AssemblyVersion("
and ")]
I understand that regular expressions will most likely be needed here, but I am having trouble understanding how to target values between two specific values. I attempted to read through the Regular-Expression.info website in hopes of understanding this better. In this, I read through Lookahead
and Lookbehind
as one such possibility, but didn't understand how to combine these expressions and there were little to no examples to get a strong grasp on how to these are used. I also thumbed through matching Complete Lines, but this also seemed to put me in a position where I would have use two separate equations to try and get the results I desire...
In my research, I found one similar approach at: Match everything between two words in PowerShell. Unfortunately, despite the mini explanation provided, I could not modify and duplicate the results to suite my need. I often encountered an error stating: 'cannot convert to regex'. I was not able to figure out what I was doing wrong and it didn't help that there was no explanation as to what the $subject
variable was referring to.
Continuing my research, the other similar variants that others asked of the above have very case specific answers that I have not been able to utilize.
I am hoping that someone here could help me to answer my question with an answer in which each piece is understandable enough to modify the answer to fit future similar problems.
Question
How can I get the value, despite the value type, that is between two strings so that I can reliably grab the AssemblyVersion
value with a single equation that is scalable enough to not care about the length of characters found? Could you also be kind enough to explain the pieces of the answer so that I can understand how you came to it?