Solved

Parse CSS value with RegEx

Posted on 2016-10-10
2
109 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

707 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