Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Regular expression and CSS

Regular expression and CSS

Scheduled Pinned Locked Moved C#
cssregex
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    emiaj
    wrote on last edited by
    #1

    Hi everyone, i need a regular expression that can extract the name and content section from each class in a css file... .Data1{color:#000000} .Data2{ color:#111111 } .Data3{ color:#222222 } the regexp should extract : .Data1 => color:#000000 .Data2 => color:#111111 .Data3 => color:#222222 Without the { or } chars Ive tried but nothing seems to work....im only be able to parse .Data1{color:#000000} using this expression (\.(.+){(.+)}) Thanks in advance.

    G 1 Reply Last reply
    0
    • E emiaj

      Hi everyone, i need a regular expression that can extract the name and content section from each class in a css file... .Data1{color:#000000} .Data2{ color:#111111 } .Data3{ color:#222222 } the regexp should extract : .Data1 => color:#000000 .Data2 => color:#111111 .Data3 => color:#222222 Without the { or } chars Ive tried but nothing seems to work....im only be able to parse .Data1{color:#000000} using this expression (\.(.+){(.+)}) Thanks in advance.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Allow for line breaks inside the brackets. Also you need to make your quantifiers non-greedy, or you will be cathing everything in the first match. (\.(.+?){\s*(.+?)\s*}) If the content contains line breaks, a period doesn't match that. (\.(.+?){\s*([\w\W]+?)\s*})

      --- single minded; short sighted; long gone;

      E 1 Reply Last reply
      0
      • G Guffa

        Allow for line breaks inside the brackets. Also you need to make your quantifiers non-greedy, or you will be cathing everything in the first match. (\.(.+?){\s*(.+?)\s*}) If the content contains line breaks, a period doesn't match that. (\.(.+?){\s*([\w\W]+?)\s*})

        --- single minded; short sighted; long gone;

        E Offline
        E Offline
        emiaj
        wrote on last edited by
        #3

        I found this article, it might be useful http://www.codeproject.com/csharp/CSSParser.asp

        G 1 Reply Last reply
        0
        • E emiaj

          I found this article, it might be useful http://www.codeproject.com/csharp/CSSParser.asp

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Nice of you to add it to the thread, so that other might benefit. :)

          --- single minded; short sighted; long gone;

          E 1 Reply Last reply
          0
          • G Guffa

            Nice of you to add it to the thread, so that other might benefit. :)

            --- single minded; short sighted; long gone;

            E Offline
            E Offline
            emiaj
            wrote on last edited by
            #5

            my pleasure, thanks to you.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups