0

I'm new in regex and i'm trying to parse the CSS file, to get the:

  • @imports "file.css"
  • url (pathtoFile)

But it fails.

Regex cssUrls = new Regex(@"(url|@import)\((?<char>['""])?(?<url>.*?)\k<char>?\)", RegexOptions.IgnoreCase);

        foreach (Match item in cssUrls.Matches(sData))
        {


            MessageBox.Show(item.Groups[2].Value);


        }

Anyone can help me please ? Thanks in advance!

John Saunders
  • 160,644
  • 26
  • 247
  • 397
SamYan
  • 1,553
  • 1
  • 19
  • 38

1 Answers1

0

You can use this pattern:

@import ([""'])(?<url>[^""']+)\1|url\(([""']?)(?<url>[^""')]+)\2\)
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125