正则表达式:保留未知子串
Regex: Keep unkknown substring
我尝试修改一组字符串。我需要更换一些未知的部分,但也要保留未知的中间部分。在记事本++中我使用了这个
作为正则表达式输入:.*(ThemeResource .*?Brush).*
和正则表达式输出:/1
结果如下:
输入:
"<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />"
"<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltMediumLowBrush}" />"
"<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundBaseMediumLowBrush}" />"
"<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlPageBackgroundAltMediumBrush}" />"
输出:
"ThemeResource SystemControlForegroundBaseHighBrush"
"ThemeResource SystemControlBackgroundAltMediumLowBrush"
"ThemeResource SystemControlForegroundBaseMediumLowBrush"
"ThemeResource SystemControlPageBackgroundAltMediumBrush"
但是使用 c#-regex 我的输出总是:"/1"
我想,c# 和 notepad++ regex 之间存在根本差异,但不明白要更改什么,因为我的 regex-input-selection 似乎按预期工作。
编辑:
我的代码:
List<string> ls = File.ReadLines(@"c:\cbTemplate.xml").ToList().Select(x=>Regex.Replace(x, ".*{(ThemeResource .*?Brush).*", @""));
我的记事本++ "Find and Replace":
要获取捕获组,请使用 </code> 而不是 <code>/1
:
List<string> ls = File.ReadLines(@"c:\cbTemplate.xml").ToList().Select(x=>Regex.Replace(x, ".*{(ThemeResource .*?Brush).*", @""));
我尝试修改一组字符串。我需要更换一些未知的部分,但也要保留未知的中间部分。在记事本++中我使用了这个
作为正则表达式输入:.*(ThemeResource .*?Brush).*
和正则表达式输出:/1
结果如下:
输入:
"<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />"
"<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltMediumLowBrush}" />"
"<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundBaseMediumLowBrush}" />"
"<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlPageBackgroundAltMediumBrush}" />"
输出:
"ThemeResource SystemControlForegroundBaseHighBrush"
"ThemeResource SystemControlBackgroundAltMediumLowBrush"
"ThemeResource SystemControlForegroundBaseMediumLowBrush"
"ThemeResource SystemControlPageBackgroundAltMediumBrush"
但是使用 c#-regex 我的输出总是:"/1"
我想,c# 和 notepad++ regex 之间存在根本差异,但不明白要更改什么,因为我的 regex-input-selection 似乎按预期工作。
编辑:
我的代码:
List<string> ls = File.ReadLines(@"c:\cbTemplate.xml").ToList().Select(x=>Regex.Replace(x, ".*{(ThemeResource .*?Brush).*", @""));
我的记事本++ "Find and Replace":
要获取捕获组,请使用 </code> 而不是 <code>/1
:
List<string> ls = File.ReadLines(@"c:\cbTemplate.xml").ToList().Select(x=>Regex.Replace(x, ".*{(ThemeResource .*?Brush).*", @""));