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?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityIn 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?
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)
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".