• Login
Community
  • Login

while search comments how to exclude in notepadd++?? i need plugin same.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 3 Posters 1.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.
  • I
    Indrk toyou
    last edited by Nov 30, 2018, 9:15 AM

    while search comments how to exclude in notepadd++?? i need plugin same.

    1 Reply Last reply Reply Quote 0
    • P
      PeterJones
      last edited by Nov 30, 2018, 2:44 PM

      Unfortunately, you haven’t described your problem in much detail , so it’s hard for us to help.

      I am guessing here, but I think you are looking for a plugin that will help you while searching the source-code you are editing – I think you want to either search just the comments, ignore matches in actual code; or, oppositely, you want to search just the actual code, and ignore matches in the comments – but I’m not sure. If this is an accurate interpretation, please let us know which one (or both, if you want either ability). Either way, I don’t know of a plugin that does that – it would probably have to be programming-language dependent (because different languages do comments in different ways – some have single-line comments, some multi-line, and some both): if my interpretation is right, please also let us know what programming language or languages you want to be able to do this in.

      If I’ve guessed wrong, please see the FAQ I linked above, and provide us with more information as to what you want.

      1 Reply Last reply Reply Quote 1
      • I
        Indrk toyou
        last edited by Dec 6, 2018, 7:03 AM

        Sorry for the inconvenience and thank you so much for your replay :) :) !!!

        Problem :
        In the C programming while search code comments also it will list. I need only source code and ignore the comments while search in the notepad++. I need plugin same.

        1 Reply Last reply Reply Quote 0
        • I
          Indrk toyou
          last edited by Dec 6, 2018, 8:36 AM

          Sorry for the inconvenience and thank you so much for your replay :) :) !!!

          Problem :
          I need only source code and ignore the comments while search in the notepad++ for c programming . I need plugin same.

          1 Reply Last reply Reply Quote 0
          • P
            PeterJones
            last edited by Dec 6, 2018, 2:21 PM

            Thank you for clarifying. Like I said, I don’t know of any plugins that do that, but there might be one.

            However, @guy038 or one of the other regex gurus might be able to come up with a regular expression that looks for foo, as long as it doesn’t come on the same line after //, and as long as it doesn’t come between /* and */ even on multiple lines. My regex ability doesn’t extend quite that far.

            Here is some example text that such a regex should handle

            void foo(void) { // match the foo to the left, but not these foo to the right
                int bar = foo(); // match this one, too
                /* bar = recurse() + foo();    // nope, it's inside multiline comment, so should be ignored
                i = foo();  // not here either
                */
                return(foo());  // but match this one
            }
            

            I started with just trying to match foo not after //, using regex=(?!//)*foo or (?!//).*foo, but neither of those worked (I am not really good at the negative lookbehinds and other “does not contain this multicharacter string” regular expressions. Some day, after reading enough of Guy’s regex, I hope to get to that level… but I’m not there yet.) And until I get that, there’s no way I could get it to also not match anything between the /* and */.

            1 Reply Last reply Reply Quote 3
            • G
              guy038
              last edited by guy038 Dec 8, 2018, 12:24 PM Dec 8, 2018, 1:30 AM

              Hello, @indrk-toyou, @peterjones and All,

              Ah ! Peter, I needed some time to figure out the correct regex, but it should, indeed, match all occurrences of the word foo, which are, both, outside multi-lines comments /*.....*/ and before any // start of a line comments ;-))

              Note that finding a regex that matches each kind of C comments was rather easy ! However taking these two features in account, in a same regex, was really a tricky work !!


              So, if options Regular expression and Wrap around are selected, in the Find/Replace/Mark dialog, a possible solution is :

              • (?-i)((?s)/\*.*?\*/((?!/\*).)*?|(?-s)(\G|^)((?!//|/\*).)*?)\Kfoo , if you want to match the word foo, with its exact case

              • (?i)((?s)/\*.*?\*/((?!/\*).)*?|(?-s)(\G|^)((?!//|/\*).)*?)\Kfoo , if you want to match the word foo, whatever its case

              So, assuming the text below ( Please, no coherent C code, Just to verify that the regex does work as expected ! )

              The regex finds /marks 21 occurrences of foo !

              "foo"                        // First match
              void foo(void)   foo  {      // Match the word foo, before //, but NOT these foo, located after FIRST //
                  foo
                  int bar = foo();    foo  // match the TWO strings "foo"
              foo
                  foo        foo           /* bar = recurse() + foo(); // foo INSIDE a multi-lines comment, so should be IGNORED
                  i = foo();               // Word "foo" still IGNORED !
                  foo  */  foo = foo * 7   // The FIRST "foo" is IGNORED, only !
              /*  foo                         A SECOND multi-lines comment, containing some foo strings
                     foo
               foo*/
                    /* foo                    And a THIRD multi-lines comment !
                foo*/
                  return( foo());          // Match "foo" BEFORE the // symbol for comment LINE
                  foo()
              foo/* foo */foo              // One-line comment block with foo, surrounded with two words "foo" OUTSIDE comment
              
              foo/**/foo                   // "foo" OUTSIDE One-line comment block
              
              foo /* foo                      Two consecutive TWO-lines comment blocks, containing foo, split on THREE lines
              */ foo  /*
              foo */  foo
              }
              s = "foo"                    // LAST item (foo)
              

              Notes :

              • Of course, you may replace the word foo by any string or, even, a complete regex !

              • This regex does not handle some oddities as, for instance, */......./* or nested multi-lines comments /*..... /*.....*/....... */

              • BEWARE : If you need to delete or replace all occurrences of the string foo, outside comments, with something else, you must use the Replace All button, exclusively and not the Replace button ( step-by-step replacement )

              • Allow me to not explain this regex, right now ! I need to think about it, again. May be an easier solution will comes to my mind ;-))

              • Probably, I just missed a very easy way ! ( In France, we have an expression : “like the tree which hides the forest” ! ) So, I’m waiting your solutions !

              Best regards,

              guy038

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