get all class name in css file

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].


[.papa]





See: stackoverflow.com/a/432503/5894241 You need to invoke regex.exec multiple times to get subsequent capturing groups.
– Nisarg Shah
Aug 14 at 5:37


regex.exec




2 Answers
2



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);





There is case it doesn't, I made an update to string, class .papa is missing now
– angry kiwi
Aug 21 at 3:39


let arr = ;
match.input.replace(pattern, function(match, g1, g2) arr.push(g1); );
console.log(arr);





While this code may answer the question, please explain what you have done to solve the problem. Code-only answers are usually not helpful to other readers, and tend to attract downvotes. See How do I write a good answer?
– Jesse de Bruijne
Aug 14 at 7:02






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj