Use System.Text.RegularExpressions.Match
.
An instance of the Match class is returned by the Regex.Match
method and represents the first pattern match in a string. Subsequent matches are represented by Match objects returned by the Match.NextMatch
method. In addition, a MatchCollection
object that consists of zero, one, or more Matc
h objects is returned by the Regex.Matches
method.
...
If a pattern match is successful, the Value
property contains the matched substring, the Index
property indicates the zero-based starting position of the matched substring in the input string, and the Length
property indicates the length of matched substring in the input string.
Because a single match can involve multiple capturing groups, Match
has a Groups
property that returns the GroupCollection
. The GroupCollection
has accessors that return each group. Match
inherits from Group
so the entire substring matched can be accessed directly. That is, the Match instance itself is equivalent to Match.Groups[0]
(Match.Groups(0)
in Visual Basic).
I suggest modifying the regex to match only a part of the input and to avoid multi-line match issues.
The filename sub-expression needs to match both upper and lower case letters.
mypattern = Regex("VARIANT_SETTINGS file ([ ._0-9A-Za-z-]+) successfully generated!");
filename = mypattern.Match(mytext).Groups[1].Value;
filename
should now be "1094_002-900208R7.0_05R01 02.hex"
.