2

In NotePad++, I want to remove everything after the third : character in a line.

So, the character would look like:

text:moretext:evenmoretext

How would I get rid of the evenmoretext?

5

You can easily do so using Regexp search and replace

The regex to use is (put this into the Find what field on the Replace tab in the search window)

^([^:]*):([^:]*):.*$

And into Replace with enter

\1:\2

(if you need the ending : too, add it to the end of the Replace with string)

TL;DR

What does this all do?

This matches the beginning of the line:

^

This tells it to match a group, that consists of "everything that is not a : character"

([^:]*)

The literal : is matched by itself

And in the end, this matches "everything until the end of the line"

.*$

(the $ matches the "end of the line")

And the replacement means "put in the first group matched, followed by a :, and then the secound group matched".

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.