I have this regex:
/(((\w+)|(\.\w+)|(\#\w+)|\*)(\[(.+(=".+"|\*".+"|\^".+"|))\])?(::|:)?)+(?=[ \S]*\{)/gm
What I'm trying to use to match CSS selectors. Consider this CSS pseudo-code input:
.main { property: value; } .one, .two a[href$=".com"] { .subclass { property: value; } } .test:before, .test:after:active {}
In the above template, the following matches will be returned:
['.body', '.one', '.two', 'a[href$=".com"]', '.subclass', '.test:before', '.test:after:active']
I am trying to change the pattern so that psuedo selectors are not matched. So all other matches must be valid, but .test:before should just be .test and .test:after:active should also just match .test . I cannot think of a way to do this without a negative appearance or a way to not match if the first character is :
I implement this in Node, and I don't want to block my script until Node> 9.2.0 in order to use negative images in my regex.
Any ideas would be greatly appreciated!
source share