How to match CSS classes only with their contents by using Python + regex

Viewed 19

I have a style.css file in which I want to select only CSS classes(with their contents) so that I use them for further purposes!

Below is how my style.css looks like and I want to match only .wallpaper .is-fullwidth .wallpapers .wallpaper .content .side .about .raf all them with their properties (contents) . I use Python 3.8 and the native re library!

html{
    background-color: #5f45bb;
    background-image: linear-gradient(to bottom right, #180cac, #d054e4);
    color: #fff;
    font-family: sans-serif;
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    min-width: 300px;
    overflow-x: hidden;
    text-shadow: 0 3px 5px rgba(0, 0, 0, 0.1);
}

a{
    color: currentColor;
    cursor: pointer;
    text-decoration: none;
}

.wallpaper .is-fullwidth{
    display: block;
    height: 100%;
    left: 0;
    top: 0;
    width: 100%;
}

.wallpapers{
    display: block;}



.wallpaper{
    background-image: url("/statics/595865.jpg");
    background-position: center;
    background-size: cover;
    opacity: 0.1;
    position: fixed;
}

.content{
    display: flex;
    position: relative;
    min-height: 100vh;
}
.side{
    max-width: 23rem;
    max-height: 20rem;
}

.about{
    max-width: 26rem;
}


.raf{
 background-image: url("/statics/595865.jpg");
    background-position: center;
    background-size: cover;
    opacity: 0.1;
    position: fixed;
}
1 Answers

This should do the job:

\..*\{[^\}]*\}

Breakdown:

  • \.: period character
  • .*: any number of any character
  • \{: A single open bracket
  • [^\}]*: Any number of anything except a close bracket
  • \}: A single close bracket

You can see it in action on your sample CSS here

Related