• Login
Community
  • Login

Replace value according to previous line

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 3.6k 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.
  • G
    geoslake
    last edited by Sep 26, 2015, 9:56 AM

    Hi guys

    Im editing sfz (a music samples standard), and would need to edit that kind of thing :

    *<region> sample=Samples\Blister Pack5\Baghhopen.wav
    lokey=0
    hikey=0
    pitch_keycenter=60

    <region> sample=Samples\Blister Pack5\Bagsnes1.wav
    lokey=1
    hikey=1
    pitch_keycenter=60

    <region> sample=Samples\Blister Pack5\Bagsnes2.wav
    lokey=2
    hikey=2
    pitch_keycenter=60*

    etc etc (hundreds of values)
    What i need to do is knda simple i guess, i need the xx value for “pitch_keycenter=” to be set according to what previous line say (hikey=yy)
    In this case i would need to respectively set the “pitch_center” values, to 0,1 and 2.
    Is there a way to achieve this in np++ ?

    Thanks a million

    CHeers

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 Sep 27, 2015, 8:40 AM Sep 26, 2015, 5:20 PM

      Hello Emmanuel,

      Well, it’s easy enough to achieve that S/R !

      • Go back to the very beginning of your file

      • Open the Replace dialog and choose the Regular Expression search mode

      • In the SEARCH zone, type ((\d+)\Rpitch_keycenter=)\d+

      • In the REPLACE zone type \1\2

      • Click on the Replace All button

      Notes :

      • \d+ represents any number (one or more consecutive digits )

      • \R is any End of Line ( \r\n for a Windows file, \n for an Unix file or \r for an old Mac file

      • The regex (\d+)\Rpitch_keycenter= stands for the group 1, which is re-written, first, (\1), in replacement

      • The first regex \d+ is the group 2 ( the number at the end of the hikey line, before the EOL and pitch_keycenter ), which is re-written, last, (\2), in replacement


      You can either use that other regex syntax :

      SEARCH = (\d+)\Rpitch_keycenter=\K\d+

      REPLACE = \1

      Notes :

      • The regex engine tries to match the regex (\d+)\Rpitch_keycenter=, and \d+ is the group 1 ( the number at the end of the hikey line

      • Then, due to the \K form, the regex engine forget the previous match and tries, now, to match the remaining. That is to say, the simple regex \d+ ( the number, at end of the pitch_keycenter line )

      • This number is, finally, replaced by the value of group 1

      • DON’T use the step-by-step Replace button, with that second syntax

      Hope these regexes will be useful to you !

      Best Regards

      guy038

      1 Reply Last reply Reply Quote 0
      • G
        geoslake
        last edited by Sep 27, 2015, 7:03 AM

        Wow, thank you very very much, guy038, you not only almost saved my life :), but you took the time to explain things extensively to me, thanks again !

        Cheers

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