Solved

Parse CSS value with RegEx

Posted on 2016-10-10
2
39 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
Comment Utility
try this one

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

Author Comment

by:ulf-jzl
Comment Utility
Thx, works perfectly :-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Chat Room 1 24
dynamic menu in asp.net c# 11 25
C# DataGridView_RowsAdded event not firing 1 36
CSS grid style change 2 13
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!
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now