Regex help: CSS comments as function names in FunctionList

  • I organise rules in my CSS files with comments, so using them to navigate a file via Function List works well for me. I came up with this in functionList.xml:

    <association langID="20" id="css_function"/>

    <parser id="css_function" displayName="CSS" commentExpr="">
    	<function mainExpr="/\*(.*?)\*/" displayMode="$functionName">
    			<nameExpr expr=".*"/>

    giving me a function list that looks like this:

    • /* nav menu */
    • /* ads */
    • /* pink outline */
    • /* search widget */

    Which is fine and useful, but not quite what I want. I’m trying to achieve simply this:

    • nav menu
    • ads
    • pink outline
    • search widget

    How do I do it?

  • Hello Lionel,

    To ONLY get, in your Function List window, the contents of the comments, without the delimiters and some extra blank characters, before and after them, just change the nameExpr line into :

    <nameExpr expr="(?-s)/\* *\K.*?(?= *\*/)"/>

    Explanations :

    • The (?-s) syntax forces the dot symbol to represent a standard character only ( not an EOL character )

    • The first part of this regex, /\* * matches the string /*, followed by the longest range, even null, of spaces

    • The \K is a special syntax that tell the regex engine to forget everything that was previously matched. So, the final regex will begin to match the first non blank character after the start delimiter /*

    • The final part of this regex (?= *\*/), is a look-ahead construction, which must be verified to get a positive match, but which is NEVER part of a regex. The regex of this look-ahead, that is to be verified, is the longest range, even null, of space characters, followed by the string */

    • The middle part of this regex .*? is the shortest range of characters between the first and the final parts, of the regex, which are to be written in the Function List window

    That should be work nice !

    Best Regards,


  • Thanks guy038 for the solution and explanation. Cheers

Log in to reply