Results 1 to 2 of 2

Thread: regex for parsing @font-face

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Edmonton, AB

    regex for parsing @font-face

    Hey all,

    I'm trying to figure out how to setup a regex that will grab everything included in a CSS @font-face declaration for parsing. I am at a loss and not great with this.

    I have an example of a regex expression that grabs everything in the way I need it for a CSS @import statement.

    var RE_IMPORT = /@import\s*(?:(?:(?:url\(\s*(['"]?)(.*)\1)\s*\))|(?:(['"])(.*)\3))\s*([^;]*);/g;
    Just ask if I'm missing any required info.


  2. #2
    Join Date
    Oct 2010
    Versailles, France
    Unless I am mistaken, this /@font-face\s*\{[^}]+}/g regular expression will capture all @fontface declaration.

    We capture all string beginning with @font-face, followed with : zero or more (*) space or tab...(\s), one opening curly brace (which is to escape with a backslash), one or more (the + sign after the closing square bracket) non (^) closing curly brace characters and one closing curly brace. The g for general will make all capture and not only the first.
    A \s* at the end of the regular expression (just before the backslash) could capture all spaces, tabulations, carriage returns or line feeds at the end of the pattern.
    Last edited by 007Julien; 02-26-2014 at 07:11 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center