-1

I have lines like that:

example1:example2:example3
example1:exa5:exa8

And I'd like to convert them into

example1:example3
example1:exa8

Is it possible to do that with regex?

Any help would be appreciated.

Thanks!

Mario
  • 1,374
  • 6
  • 22
  • 48
  • 1
    Why is this question too broad? – Paolo Aug 16 '18 at 09:10
  • 1
    @UnbearableLightness The same reason I gave on the answer before all the comments were removed: [Should “Give me a regex that does X” questions be closed?](https://meta.stackoverflow.com/questions/285733/should-give-me-a-regex-that-does-x-questions-be-closed) + [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Nick is tired Aug 16 '18 at 09:22
  • I see, I have seen many questions with the regex tag with the same format as this one remain open... – Paolo Aug 16 '18 at 10:12
  • @UnbearableLightness Well then they should be closed – Nick is tired Aug 16 '18 at 10:14
  • I'll bear that in mind and will report them without answering the question. – Paolo Aug 16 '18 at 10:15
  • @UnbearableLightness It's not necessary to, everyone is welcome to do what they would like to do, that's just my personal opinion, you can take what you want from the links that I gave in my comment above and decide your preference. Just bear in mind that some users *may* downvote answers on questions where it is believed that the OP hasn't made enough of an effort to deserve one. – Nick is tired Aug 16 '18 at 10:30

2 Answers2

0

In Find what use:

(?<=:)[a-z0-9]+:

Replace with empty string.

The expression:

  • (?<=:) Positive lookbehind for :.
  • [a-z0-9]+ Match lower case letters and numbers.
  • : Match :.
Paolo
  • 21,270
  • 6
  • 38
  • 69
0
  • Ctrl+H
  • Find what: :[^:\r\n]+(?=:)
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

:           # a colon
[^:\r\n]+   # 1 or more any character that is not a colon or line break
(?=:)       # positive lookahead, make sure we have a colon after

Result for given example:

example1:example3
example1:exa8
Toto
  • 89,455
  • 62
  • 89
  • 125