Regular expression
-
Hello, I am writing a regular expression to divide a CSS file into rules like this;
#DTEST
{
border-style:solid;
border-width:thin;
}I want to repeat a part of the pattern to match all attributes enclosed between the tow braces the pattern I want to repeat looks like this: [\n\t\\s]*[a-zA-Z\\-]+[\\s]*:[\\s]*[a-zA-Z\\-]+[\n\t\\s]*
Dad
-
Hello, I am writing a regular expression to divide a CSS file into rules like this;
#DTEST
{
border-style:solid;
border-width:thin;
}I want to repeat a part of the pattern to match all attributes enclosed between the tow braces the pattern I want to repeat looks like this: [\n\t\\s]*[a-zA-Z\\-]+[\\s]*:[\\s]*[a-zA-Z\\-]+[\n\t\\s]*
Dad
-
I want to repeat a part of the pattern to match all attributes enclosed between the two braces the pattern I want to repeat looks like this: [\n\t\\s]*[a-zA-Z\\-]+[\\s]*:[\\s]*[a-zA-Z\\-]+[\n\t\\s]* How to repeat this pattern? this pattern allows application to validate only one attribute like this color:red; but if there is a lot of attributes i don't know How to make the pattern match them all?
Dad
-
I want to repeat a part of the pattern to match all attributes enclosed between the two braces the pattern I want to repeat looks like this: [\n\t\\s]*[a-zA-Z\\-]+[\\s]*:[\\s]*[a-zA-Z\\-]+[\n\t\\s]* How to repeat this pattern? this pattern allows application to validate only one attribute like this color:red; but if there is a lot of attributes i don't know How to make the pattern match them all?
Dad
-
I want to repeat a part of the pattern to match all attributes enclosed between the two braces the pattern I want to repeat looks like this: [\n\t\\s]*[a-zA-Z\\-]+[\\s]*:[\\s]*[a-zA-Z\\-]+[\n\t\\s]* How to repeat this pattern? this pattern allows application to validate only one attribute like this color:red; but if there is a lot of attributes i don't know How to make the pattern match them all?
Dad
Here you go, I even tested it for you...your pattern appears to work fine and dandy:
string input = @"#DTEST
{
border-style:solid;
border-width:thin;
}";string pattern = "[\n\t\\s]*[a-zA-Z\\-]+[\\s]*:[\\s]*[a-zA-Z\\-]+[\n\t\\s]*";
MatchCollection mc = Regex.Matches(input, pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
Console.WriteLine(mc.Count);
foreach (Match m in mc)
{
Console.WriteLine(m.Value.Trim());
}// output:
// 2
// border-style:solid
// border-width:thin -
Here you go, I even tested it for you...your pattern appears to work fine and dandy:
string input = @"#DTEST
{
border-style:solid;
border-width:thin;
}";string pattern = "[\n\t\\s]*[a-zA-Z\\-]+[\\s]*:[\\s]*[a-zA-Z\\-]+[\n\t\\s]*";
MatchCollection mc = Regex.Matches(input, pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
Console.WriteLine(mc.Count);
foreach (Match m in mc)
{
Console.WriteLine(m.Value.Trim());
}// output:
// 2
// border-style:solid
// border-width:thinThanks a lot, I know that the pattern works well in the way you use it for getting the attributes inside these two braces {} but what I've failed to do is to match the whole rule like this:
#DTEST
{
border-style
: solid ;
border-width : thin ;
position:relative;
right:10px;
left:900px;
width:50px;
}This is the whole pattern: [\\.#]?[a-zA-Z0-9_]+[\n\t\\s]*{[\n\t\\s]*[a-zA-Z\\-]+[\\s]*:[\\s]*[a-zA-Z\\-]+[\n\t\\s]*;[\n\t\\s]*}
but it works only if the css rule contains only one attribute like this:
.Red
{
color:Blue;
}the question is how can I let it match the css rule even if it has multiple attributes.
Dad