• Login
Community
  • Login

Mark all text who have word searched

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 3 Posters 976 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.
  • E
    ElBriak Badr
    last edited by May 8, 2022, 11:43 AM

    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

    A 1 Reply Last reply May 8, 2022, 12:15 PM Reply Quote 0
    • A
      Alan Kilborn @ElBriak Badr
      last edited by May 8, 2022, 12:15 PM

      @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.

      E 1 Reply Last reply May 8, 2022, 12:25 PM Reply Quote 2
      • E
        ElBriak Badr @Alan Kilborn
        last edited by May 8, 2022, 12:25 PM

        @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
        • G
          guy038
          last edited by May 8, 2022, 9:38 PM

          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

          E 1 Reply Last reply May 9, 2022, 8:19 AM Reply Quote 3
          • E
            ElBriak Badr @guy038
            last edited by May 9, 2022, 8:19 AM

            @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
            • G
              guy038
              last edited by guy038 May 9, 2022, 11:03 AM May 9, 2022, 10:51 AM

              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

              E 1 Reply Last reply May 9, 2022, 11:06 AM Reply Quote 2
              • E
                ElBriak Badr @guy038
                last edited by May 9, 2022, 11:06 AM

                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
                4 out of 7
                • First post
                  4/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors