I'm trying to use Gembox.Document to search a docx file for a tag and to retrieve the value held within the tag. The tag will always be
var pattern = Regex.Escape("<!(.*?)!>");
To get all the values you need use
Regex.Matches instead of the
var res = Regex.Matches(s, @"<!(.*?)!>") .Cast<Match>() .Select(s => s.Groups.Value) .ToList();
Regex.Escape is only used to escape literal strings to be used inside regular expression patterns, e.g.
. will become
\. to match a literal dot symbol.
Regex.Match searches for a single match, while
Regex.Matches will return all non-overlapping matches. Since you need just Group 1 value, the
Select clause is quite handy here and
.Select(s => s.Groups.Value) returns just those values that are captured with Group 1 in the pattern.
See this online C# demo