• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Parse CSS value with RegEx


I need some help to parse a CSS value (A5, from page size) using RegEx.

This is the part of the CSS code:

@page {
   size: A5;
   margin: 0;

Open in new window

The code I now have only extracts the inner text of the @page group, not the actual A5 value.

 const string expression = "(?<=@page {)(.*)(?=})";
 var regEx = new Regex(expression, RegexOptions.Singleline | RegexOptions.IgnoreCase);
var match = regEx.Match(styleSheet);

Open in new window

I have a solution where I parse the A5 value using Linq, but I would like to do all the parsing using RegEx, if possible.
1 Solution
try this one

.*@page\s*{[^}]*\ssize\s*:\s*([^; ]+)\s*;.*
ulf-jzlAuthor Commented:
Thx, works perfectly :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now