Community
    • Login

    Mark all text who have word searched

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 950 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.
    • ElBriak BadrE
      ElBriak Badr
      last edited by

      I have a text file like the folowing one:

      #TEST Random TEXT |
      
      #TEST Random TEXT:
      Random TEXT special Random TEXT |
      
      #TEST Random TEXT:
      Random TEXT  |
      
      #TEST Random TEXT:
      Random TEXT special Random TEXT
      Random TEXT 
      Random TEXT 
      Random TEXT  |
      

      I want to mark text who contain this word “special”
      The result can be :

      #TEST Random TEXT:
      Random TEXT special Random TEXT |
      
      #TEST Random TEXT:
      Random TEXT special Random TEXT
      Random TEXT 
      Random TEXT 
      Random TEXT  |
      

      I trying to use this
      ^(#TEST).+?special+?\|$
      but the result not correct

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @ElBriak Badr
        last edited by

        @elbriak-badr

        I think a clarification for those that want to help is:

        You want to mark multiple lines of text that occur between single empty lines, that contain the text special.

        ElBriak BadrE 1 Reply Last reply Reply Quote 2
        • ElBriak BadrE
          ElBriak Badr @Alan Kilborn
          last edited by

          @alan-kilborn Thanks For your Reply ,
          The text like you see is started by # and ended by |

          I need to mark all text who have the word special

          1 Reply Last reply Reply Quote 0
          • guy038G
            guy038
            last edited by

            Hello, @elbriak-badr , @alan-kilborn and All,

            So you need to mark any range of text beginning with a # character, having the word special in the next line and then mark all chars till the nearest | character

            In this case, the road map is :

            • Open the Mark dialog ( Ctrl + M )

            • Find what : (?-is)^#TEST.+\R.+special(?s).+?\|

            • Un-tick all options

            • Tick the Bookmark line, Purge for each search and Wrap around options

            • Select the Regular expression search mode

            • Click on the Mark All button

            • Now, you can, either :

              • Click on the Copy Marked text button and paste the clipboard contents in a new tab

              • Choose the menu option Search > Bookmark > Copy Bookmarked lines and paste the clipboard contents in a new tab


            Notes,

            • The search is sensitive to case, due to the in-line modifier -i ( so, not insensitive ! )

            • At beginning any . matches a single standard char ( so, not the line-endings )

            • After the word special, the in-line modifier (?s) means that dot matches any character, including EOL ones

            Best Regards,

            guy038

            ElBriak BadrE 1 Reply Last reply Reply Quote 3
            • ElBriak BadrE
              ElBriak Badr @guy038
              last edited by

              @guy038 Thanks a lot , it’s working for any range of text beginning with a # character, having the word special in the next line , but can you please help me to search for range of text having the word special in any line ?

              #TEST Random TEXT |
              
              #TEST Random TEXT:
              Random TEXT special Random TEXT |
              
              #TEST Random TEXT:
              Random TEXT  |
              
              #TEST Random TEXT:
              Random TEXT 
              Random TEXT 
              Random TEXT special Random TEXT
              Random TEXT  |
              
              #TEST Random TEXT:
              Random TEXT 
              Random TEXT special Random TEXT
              Random TEXT 
              Random TEXT  |
              

              Results

              #TEST Random TEXT:
              Random TEXT special Random TEXT |
              
              #TEST Random TEXT:
              Random TEXT 
              Random TEXT 
              Random TEXT special Random TEXT
              Random TEXT  |
              
              #TEST Random TEXT:
              Random TEXT 
              Random TEXT special Random TEXT
              Random TEXT 
              Random TEXT  |
              
              1 Reply Last reply Reply Quote 0
              • guy038G
                guy038
                last edited by guy038

                Hi, @elbriak-badr , @alan-kilborn and All,

                Ah…, OK. In this case, we must use the (?s) modifier for the entire regex.and the goal becomes :

                • A) To look for any range of text, between the string #TEST, beginnning a line, till the nearest | character

                • B) This range must, of course, contains the word special

                • C) The string #TEST, itself, must never occur, after each #TEST string till the word special !


                Thus, the appropriate regex is :

                SEARCH (?s-i)^#TEST((?!#TEST).)+?special.+?\|


                Notes :

                • To achieve the C) condition, we use a negative look-ahead condition, meaning that the range of chars, after #TEST, till the word special, must not contain the #TEST string, itself, at any position, thanks to this specific syntax ((?!#TEST).)+?

                • The -i syntax, at beginning of the regex, means that the search is sensitive to case ( so not insensitive ! ) If you need a search, whatever the case, change the part (?s-i) by (?si)

                Best Regards,

                guy038

                ElBriak BadrE 1 Reply Last reply Reply Quote 2
                • ElBriak BadrE
                  ElBriak Badr @guy038
                  last edited by

                  Very wonderful ,
                  Thanks a lot @guy038 ,
                  that make me love notepad++ more !!

                  I am grateful for your support.

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