Explain regex that finds CSS comments

后端 未结 2 1424
离开以前
离开以前 2021-02-09 09:55

I found this regex code that finds comments in w3.org\'s CSS grammar page.

\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/
         


        
2条回答
  •  粉色の甜心
    2021-02-09 10:32

    Token by token explanation:

    \/    <- an escaped '/', matches '/'
    \*    <- an escaped '*', matches '*'
    [^*]* <- a negated character class with quantifier, matches anything but '*' zero or more times
    \*+   <- an escaped '*' with quantifier, matches '*' once or more
    (     <- beginning of group 
    [^/*] <- negated character class, matches anything but '/' or '*' once
    [^*]* <- negated character class with quantifier, matches anything but '*' zero or more times
    \*+   <- escaped '*' with quantifier, matches '*' once or more
    )*    <- end of group with quantifier, matches group zero or more times
    \/    <- an escaped '/', matches '/'
    

    Regex Reference

    Analysis on Regexper.com

提交回复
热议问题