Reputation: 540
I try to modify a set of strings. I need to replace some unknown parts but also keep the unkknown middle part. In notepad++ I used this
as regex-input: .*(ThemeResource .*?Brush).*
and regex-output: /1
with this result:
Input:
"<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />"
"<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltMediumLowBrush}" />"
"<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundBaseMediumLowBrush}" />"
"<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlPageBackgroundAltMediumBrush}" />"
Output:
"ThemeResource SystemControlForegroundBaseHighBrush"
"ThemeResource SystemControlBackgroundAltMediumLowBrush"
"ThemeResource SystemControlForegroundBaseMediumLowBrush"
"ThemeResource SystemControlPageBackgroundAltMediumBrush"
but with c#-regex my output is allways: "/1"
I guess, there are fundamental differences between c# and notepad++ regex, but do not understand what to change, since my regex-input-selection seems to work as expected.
Edit:
My code:
List<string> ls = File.ReadLines(@"c:\cbTemplate.xml").ToList().Select(x=>Regex.Replace(x, ".*{(ThemeResource .*?Brush).*", @"\1"));
My notepad++ "Find and Replace":
Upvotes: 2
Views: 60
Reputation: 29451
To get the capturing group, use $1
instead of /1
:
List<string> ls = File.ReadLines(@"c:\cbTemplate.xml").ToList().Select(x=>Regex.Replace(x, ".*{(ThemeResource .*?Brush).*", @"$1"));
Upvotes: 2