I hope I find you well.
I realise that a generic regular expression to fit all css won't cut it in all cases, however I am parsing a particular piece of css so I can tweak this expression to fit my needs.
Having scoured SO, I did find some very useful regular expressions which I have combined with great success into the following:
parsed_css = re.findall(r'([\[\]=\"\#\.\w\-\,\s\n\r\t:@*]+)(\{[^\{\}].*?\})', css, re.DOTALL)
This produces something like:
Selector: '.div-wrapper' rules: '{position:absolute;z-index:4;background:none!important;border:none!important}'
However, I encounter problems when coming across keyframes rules like this:
@keyframes mymove { from {top: 0px;} to {top: 200px;}}
Obviously the curlies are the problem but I'm hoping someone has some look ahead / look behind magic to produce the following in these rare instances:
Selector: '@keyframes mymove'
Rules: '{from {top: 0px;} to {top: 200px;}}'
Many thanks! Darren