Marking a large text



  • Hi! I’ve just used notepad++ and had a great experience with it. I’ve got a question regarding marking a larger text. Is there any way in notepad++ to search for a text and mark from the current writing location to the searched text? I’ve got a text as following

    A
    xx
    b
    A
    xx
    b

    I manually find A and have to scroll down tons of text in order to get to B, in order to shift click b. Would there be a plugin or a method for me to click A, search for b and the xx between A and B would get marked.



  • Hello, Erik,

    There’s a simple method, using a search, in regular expression mode !

    It’s not exactly what you would like to, because you’ll need to type the two limits, inside the regular expression search, instead of clicking on the first limit and searching for the second one.

    Anyway, it’s works fine :-)

    Then, let’s suppose the subject text, below :

    aa
    bb
    Begin
    xx
    yy
    End
    
    Begin
    
    vv
    ww
    xx
    yy
    zz
    
    End
    
    12345 Begin 67 89 01 23 45 End 67890
    

    Now, follow the few steps, below :

    • Open the Search dialog

    • Choose the Regular expression search mode

    • Check the Wrap around and/or Match case options, if necessary

    • In the Find what zone, type the regex (?s)Begin\R?\K.*?(?=End)

    • Finally, click on the Find Next button

    Notes :

    • This regex select all the lines, located between the line Begin and the nearest line End OR all the text, between two strings Begin and End, located on the same line

    • The modifier (?s) means that any dot, in the expression, matches any character, even End of Line characters

    • The regex tries, first, to match the string Begin, eventually followed by its End of Line characters \R?

    • Then the \K syntax forces the regex engine to forget any previous match. So, the regex to match is, ONLY, .*?(?=End)

    • Therefore, the regex matches any character, even End of Line characters, till the nearest string End, which is, however, NOT part of the final match, too, because it’s included in a lookahead structure (?=....)

    • Of course, the strings Begin and End can be replaced by a simple character, like A and B or by regexes, like [01234] and [56789], or, even, more complex regexes !

    IMPORTANT :

    If you intend to replace these selected blocks by any text, or delete them, you must use the global replacement, clicking on the Replace All button and NOT the Replace button, because of the presence of the \K form !

    Best regards,

    guy038

    P.S. :

    You’ll find good documentation, about the new Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v1.48.0 ), used by Notepad++, since its 6.0 version, at the TWO addresses below :

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

    • The FIRST link explains the syntax, of regular expressions, in the SEARCH part

    • The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part



  • While I like the elegance of guy038’s solution, it may be worth pointing out that the “Begin/End Select” feature could also be utilized to solve the original problem. Do a Find on the first text, then enable Begin/End Select via the Edit menu choice, right-click context menu, or shortcut key, doing so with the caret just after the found text. Then do another Find on the ending text, and end/turn-off the Begin/End Select feature (before doing this it will be enabled/checked on the Edit menu) after moving the cursor just before the found text from this second find.



  • Hi Erik and Scott,

    Oh, yes, Scott, I forgot this obvious solution :-(

    In addition, since the N++v6.4.2 version, the Begin/End Select, command is recordable in a macro :-)

    The nice thing, with N++, is that there are, very often, several ways to achieve the same goal !

    Cheers,

    guy038


Log in to reply