I need to select all classes names in a css file, I am just new at it, also if someone can advice some good online tutorials for regex is appreciated.
Regex will be used in JavaScript
I came with this which works for simple classes:
/(?<=\.).+?(?=\{)/g
.className {
}
the above regex returned this: className
now I need to add for this too:
tagName1 {
}
#tagName2 {
}
.tagName3:hover {
}
.tagName4:anything {
}
should result in: tagname1 tagname2 tagname3 tagname4
So how to select the above ones?
(?<=\.|^|#)\w+(?=\s?{). You should also edit your question and include the language you are using.classNameis not a class name, it's a tag name. And#classNameis an ID, not a class name. What about more complex CSS selectors, like.classname:hover?