Solved

Parse CSS value with RegEx

Posted on 2016-10-10
2
69 Views
Last Modified: 2016-10-11
Hi!

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.
0
Comment
Question by:ulf-jzl
2 Comments
 
LVL 26

Accepted Solution

by:
skullnobrains earned 500 total points
ID: 41838012
try this one

.*@page\s*{[^}]*\ssize\s*:\s*([^; ]+)\s*;.*
0
 

Author Comment

by:ulf-jzl
ID: 41838124
Thx, works perfectly :-)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question