Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:43:56+00:00 2026-06-18T10:43:56+00:00

I want to split a border attribute from CSS into its constituent parts i.e:

  • 0

I want to split a border attribute from CSS into its constituent parts i.e:

.someClass{
  border: 1px solid black;
}

Into

border-width: 1px
border-style: solid;
border-color: black;

I have split off the border: and semi-colon before this, so I simply need to parse the value section of the attribute

Now in CSS you can have any combination of the 3 above attributes present so

border: 1px solid;
border: solid Gold;
border: 1em;
border: 1mm #000000;
border: 1px inset rgb(12, 44, 199);

All are legal so I need to account for that.

What I have so far is

([0-9]+[a-zA-Z|%]+)* *([a-zA-Z]*) *( .*)

Which works fine for the normal case, but fails on the “1px Solid” case as Solid is put into the 3rd capturing group, not the 2nd. I am not a regex expert so I may be making very basic mistakes, but any help would be greatly appreciated. I am working with C# (but have mainly been testing in http://gskinner.com/RegExr/ so any differences might have been the problem)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:43:58+00:00Added an answer on June 18, 2026 at 10:43 am

    Simply including border: at the start of the expression seems to be a major help since it won’t accidentally match the second or third group. Similarly, adding ; to the end of the expression prevents capture of the second or third group too early. Other than that, changing the second group from * to + also helps because that allows it to match the second group as intended rather than the third. Altogether, try this:

    border: ([0-9]+[a-zA-Z|%]+)* *([a-zA-Z]+)* *( .*)*;
    

    I doubt that this is perfect and if you need results to work 100%, you probably should not use a single regular expression but instead tokenize and parse the string (I highly doubt CSS rules are parsed entirely with regex), but if this works for the limited rules you need it for then great.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to split a file(suppose a mp3) into four parts.I have tried this
I want to split a string in Javascript using split function into 2 parts.
I want to split and transpose a multiline string from one DataGridView(dgvObs) to separate
I want to split a string like this: abc//def//ghi into a part before and
We want to split our large asp.net mvc web application into multiple Visual Studio
I want to split a file containg HTTP response into two files: one containing
I have the following array: $array = array(1,0,0,0,1,1,1,1,0,1,1,1,1,0,1,1,0,1,0,0,1,0,1); I want split it up into
I want to split the Birthdate column in my database.. Returned String from database
I want split integers into their factors. For example, if the total number of
I want to split the legend on a plot into 2, so that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.