How to extract specific parts of a large batch of strings

notepad

For example.

64d134a354eb2bf43626a73091514a2d:QMP0R\khOiPmkW1>bP,_-NTY4%-!P#:a123456
7d057d46b88f2cf4845dec57be4f3158:iR+LE[SQ\R~~o*+CCNL?i)mC>$G:U#:123321
6e0c116855a273f0c8c41dec1d21c160:s'?:fL2/mVj{&[`Onkyqf"y~47^YU#:abc123

All strings follow a three part pattern. The first two parts each separated by a colon and the required element following the second colon.

Exception: In part two of the string, there also exists the occasional colon. (see the third line ending in "abc123")

My proposal would be to reverse all of the strings and, once done, eliminate all characters after and including the first colon. When completed, reverse the text again to end up with the required elements, which should read:

a123456
123321
abc123

Note: This is to be applied to a large batch of such strings!

Best Answer

In Notepad++, you can use its Find & Replace feature to remove everything before the third segment.

Simply use this find, with the Regular Expressions radio button on:

^.*:(?!.*:)

And replace by nothing, then hit Replace All.

enter image description here

What the expression means is:

^       Ensure match begins at the start of the line
.*      Match any number of characters
:       Until it matches a colon (:)
(?!     And ensure that after the colon, there are no...
  .*:   Colon after any number of characters on the same line
)

Result:

enter image description here


If the third part can contain colons as well, but it will always start with #: when compared to the other parts, then you can use a slightly different expression for the find:

^.*#:

And replace with nothing.

Related Question