Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get all class name in css file

I got css file like this :

let string =

    .papa, .aka {
        color:red
    }
    .mama .ok {
        color:blue
    }

    div .chacha{
        transition: opacity 0.2s;
    } .sasa {
        background:url(home.png)
    }

I want to fetch all the class name in the file and put in array. Expected result :

[.papa, .aka, .mama, .ok, .chacha, .sasa]

My try :

let pattern = /(?:[\.]{1})([a-zA-Z_]+[\w-_]*)(?:[\s\.\{\>#\:]{1})/igm

let match = pattern.exec(string);

console.log(match);

I only got [.papa].

like image 242
angry kiwi Avatar asked Oct 25 '25 06:10

angry kiwi


1 Answers

You can use the string.match

let string =
`
    .papa, .aka {
        color:red
    }
    .mama .ok {
        color:blue
    }

    div .chacha {
        transition: opacity 0.2s;
    } .sasa {
        background:url(home.png)
    }
`
var arr = string.match(/(?:[\.]{1})([a-zA-Z_]+[\w-_]*)(?:[\s\.\,\{\>#\:]{0})/igm);
console.log(arr);
like image 118
Rahul Sharma Avatar answered Oct 26 '25 21:10

Rahul Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!