Solved

Parse CSS value with RegEx

Posted on 2016-10-10
2
90 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 29
"The resource cannot be found" 1 24
Need help with another query 10 39
Incorrect css styling in footer 3 7
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…

726 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