Search code examples
regexnotepad++emeditor

How would I match all data between 2 symbols with Regex?


I'm trying to find all data (including and after) a dash (-) appears, only up to the first delimiter which is a colon.

Example data:

Input:
bart23-testaccount@test.test:Test:Test:Test

Desired output:
bart23:Test:Test:Test

I've done some research and found this regex, but it's not fit for purpose -(.*):

My purpose is for thousands of lines which are all in various types of order, however the purpose remains the same, highlight all text between the - and the first : (which I will then proceed to delete). I will be using Notepad++

I can answer any questions or make my post more specific if need be, it's kind of hard to explain.


Solution

  • In Notepad++ you can use regex find/replace. Look for:

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

    which captures everything up to the first - in group 1, and everything after (and including) the first : in group 2, and replace with

    \1\2