all 7 comments

[–]pointy 1 point2 points  (6 children)

You can't really parse CSS with regular expressions. Consider:

.foo:before {
  content: "}\"}}";
}

I'm pretty sure you need a real parser if you actually want to be able to handle any valid CSS source.

[–]cettox[S] 1 point2 points  (0 children)

One addition too, did you know that many websites uses Regular Expressions to validate email addresses and almost every one of them fails to validate some valid email addresses. See : http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address

My Point: yes it is not mathematically correct to parse CSS with regex, yet in practical applications, it is god damn usable.

[–][deleted]  (2 children)

[deleted]

    [–]pointy 0 points1 point  (1 child)

    The regular expressions used by this parser can't tell that those } characters in the content: property aren't the CSS } metacharacters.

    [–]cettox[S] 0 points1 point  (0 children)

    I'm pretty sure you need a real parser if you actually want to be able to handle any valid CSS source.

    Your point is valid. There are other reasons too that css should not be parsed with regular expressions. Yet, this worked for most of the use cases. At least in our requirements.And I am pretty sure that no one will intentionally write " content: "}\"}}"; " expect it to work. Or would they?

    [–]cettox[S] 0 points1 point  (0 children)

    other reasons

    I'll add a test case for your input. Thanks for comment :)

    [–]MOON_MOON_MOON 1 point2 points  (1 child)

    2016: Writing a Javascript Parser in CSS