Seach a word and pick the 100th result



  • I search a word in my notefile and i find 15000 results now I want to locate where is the 100th result in my notefile. How can i detect it ?



  • @Tarık
    may I direct you to this posting.
    https://notepad-plus-plus.org/community/topic/16104/how-to-find-and-highlight-a-specific-occurance-of-a-symbol

    The question there fits what you are trying to do. Have a go using that information. If in doubt come back to us with what you have tried and also an example of the data if possible. Real data/examples are ALWAYS so much better to help out posters.

    Terry



  • Hi, @tarik, @terry-r and All,

    From any starting point, in file, the generic regex (?s)(?:.*?(X)){N}.*?\K\1 will find the Nth occurrence of X, where X can be, either :

    • A simple character

    • A word => The regex \b<Word>\b

    • A string of characters

    • A regular expression


    For instance, the regex (?s)(?:.*?(\bthe\b)){9}.*?\K\1 would find, from current location, the 10th occurrence of the article the

    Cheers,

    guy038



  • @guy038 said:

    (?s)(?:.?(\bthe\b)){9}.?\K\1

    Thank you for kindly answers. I don’t know where can I use this command in notepad++.



  • @Tarık

    • Move your caret/cursor to the place where you want to start seeking the Nth match from
    • Invoke the Find dialog by pressing ctrl+f
    • Select Regular expression as the Search mode
    • Put an expression such as @guy038 's in the Find what zone
    • Tick the Match case checkbox if you want to…umm…only match the case of your text in the Find what
    • Press Find Next button

    Does that make it clear?



  • Thank you all!



  • Hi, @tarik, @scott-sumner, @terry-r and All,

    Thanks, Scott, for your additionnal information. Look like I was a bit tired to develop ;-))

    Of course, as Scott mentioned, your can, either, perform a sensitive to case OR a insensitive to case search, with the respective generic regexes :

    • (?s-i)(?:.*?(X)){N}.*?\K\1 ( Sensitive )

    • (?si)(?:.*?(X)){N}.*?\K\1 ( Insensitive )

    Cheers,

    guy038


Log in to reply