Community
    • Login

    ENHANCEMENT - select ONLY X nth occurence of String using REGEX

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 2 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.
    • Bernard SchleichB
      Bernard Schleich
      last edited by

      Hello,

      One month ago I searched a Regex expression to find the X nth occurence of a String in a XML file.

      On the web, I have found this expression (?s)(?:.*?<row){100} that search the 100 nth occurence of the string “<row”

      The problem with Notepad is that it does’nt display/select the 100 nth occurence but all the occurence from 1 to 100 !

      I have tested the following Regex expression using ONLY GROUPING (begin with ?:) expression and a final CAPTURING expression

      (?s)(?:.?<row){99})(.?<row)

      and I have the same result.

      MY REQUEST

      I want that if I give the previous Regex search expression that notepad display/select only CAPTURED part !

      It is certainly easy to implement when there are only one capture string !

      Can somebody implement this enhancement in Notepad++ ?

      Another approach would be to add a numeric input field in which the user can specify the number of occurence to find !

      Best regards

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • Scott SumnerS
        Scott Sumner @Bernard Schleich
        last edited by

        @Bernard-Schleich said:

        (?s)(?:.?<row){99})(.?<row)

        Try this regular expression:
        (?s)(?:.*?<row){99}.*?\K<row

        The key part is the \K syntax. It tells the regular expression engine to match but don’t include in the resultant match anything that comes before it. Thus, in the example above, only your desired <row text will be highlighted (i.e., selected) by Notepad++ after you do a Find.

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