I have this text:

D5 0.25 8;0.25 E5 0.25 8;0.5 F#5 1 8;1.5 E5 1 8;2.5 D5 1 8;3.5 B4 1 8;4.5 A4

Except, it's 800 characters long... For example, I would like to get the text between D5 and E5 and replace it with a single space. So it looks like this D5 E5, but as I said there are different values between each one.


As long as "D5" and "E5" do not appear inside the block, you can use Regular Expressions:

Search for: D5.*?E5
Replace with: D5 E5

Remember to enable regular expression search mode


Given that I recognize this as MIDI data, I assume you want to remove all midi data except for their notes, separated by a space.

You will want to use the following regex pattern for that:

Seach for ([A-Z]#*.).+?;.+?  (note the space at the end. I used ALT+255 because SuperUser removes it otherwise.)
And replace for: \1  (also note the space at the end, also ALT+255 there.)

It will make all replacements except for the very last note, unless there's a space at the end too.

The regex explained:

(                - Start Capture group
  [A-Z]          - Search for any char between A and Z, exactly 1 time
  #*             - Search for a # 0 or more times
  .              - Search for any character exactly 1 time.
)                - End capture group
                 The above search will result in the midi note, eg A3 and store it in \1

.+?              - Continue to search for any character 1 or more times in non-greedy way.
;                - Search until we find the first ;
.+?              - Search for any character 1 or more times in non-greedy way.
                 - search until we find a space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.