• Login
Community
  • Login

Regex help: CSS comments as function names in FunctionList

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
regexfunctionlist
3 Posts 2 Posters 2.9k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L
    Lionel Wong
    last edited by Oct 23, 2015, 7:56 AM

    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">
    		<functionName>
    			<nameExpr expr=".*"/>
    		</functionName>
    	</function>
    </parser>
    

    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?

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 Nov 29, 2020, 12:14 AM Oct 24, 2015, 11:00 AM

      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,

      guy038

      1 Reply Last reply Reply Quote 0
      • L
        Lionel Wong
        last edited by Oct 26, 2015, 2:41 AM

        Thanks guy038 for the solution and explanation. Cheers

        1 Reply Last reply Reply Quote 0
        2 out of 3
        • First post
          2/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors