以下の正規表現を使用して、次のステートメントと一致させています。
@import URL(normalize.css); @import URL(style.css); @import URL(helpers.css);
/// <summary>
/// The regular expression to search files for.
/// </summary>
private static readonly Regex ImportsRegex = new Regex(@"@import\surl\(([^.]+\.css)\);", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
これは私のステートメントと一致していますが、一致からグループを取得しようとすると、期待する値ではなく完全な結果が得られます。
例 期待される結果normalize.css
実際の結果@import url(normalize.css);
これを行うコードは以下のとおりです。誰が私が間違っているのか教えてもらえますか?
/// <summary>
/// Parses the string for css imports and adds them to the file dependency list.
/// </summary>
/// <param name="css">
/// The css to parse.
/// </param>
private void ParseImportsToCache(string css)
{
GroupCollection groups = ImportsRegex.Match(css).Groups;
// Check and add the @import params to the cache dependancy list.
foreach (string groupName in ImportsRegex.GetGroupNames())
{
// I'm getting the full match here??
string file = groups[groupName].Value;
List<string> files = new List<string>();
Array.ForEach(
CSSPaths,
cssPath => Array.ForEach(
Directory.GetFiles(
HttpContext.Current.Server.MapPath(cssPath),
file,
SearchOption.AllDirectories),
files.Add));
this.cacheDependencies.Add(new CacheDependency(files.FirstOrDefault()));
}
}