Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

javascript capture css rule block in string

How to capture css rule block in a string?
This is too hard for me to capture, without the new line

.fa { color: red; }
small { font-size: 16px; }
#content { background-color: blue; }

What I want to accomplish is to get each those block into array

['.fa { color: red; }', 'small { font-size: 16px; }', '#content { background-color: blue; }']

Is this possible in javascript regex?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

UPDATE

Sorry guys, I Thought this is only solvable with regex,
But got an answer which is way simpler, Thanks

>Solution :

Split by a closing curly brace:

const str = `.fa { color: red; }
small { font-size: 16px; }
#content { background-color: blue; }
`

const res = str.split("}").map(e => e += "}")
console.log(res)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading