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
Solved

Parse CSS value with RegEx

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

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

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.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

790 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