regexnotepad++

regex for replacing with tab


I am having a large data base around 80k data. There is customer reference number followed by customer name. The problem is customer reference number may have alphabets, special characters and so on. But the characters will be in upper case letter only and it will not be more than two characters and never lowercase letters.

So, I'm trying to use regular expression to search a uppercase followed by two lowercase letters.

I succeeded in doing so, by using the expression

(.)[(A-Z)][(a-z)][(a-z)]

But I don't know how to give tab, as replacing it with \t \1 deletes the first three character. Please help. and also please explain me, how it works.


Solution

  • If I understood your question correctly, you want to separate the reference number from the name. If so, in Notepad++, go to Search > Replace menu (shortcut CTRL+H) and do the following:

    1. Find what:

      ^.+?\K(?=[A-Z][a-z])
      
    2. Replace with:

      \t
      
    3. Select radio button "Regular Expression"

    4. Then press "Replace All"

    This will convert the following hypothetical example:

    E34E!John Doe
    123$#@ERFrank
    

    To:

    E34E!    John Doe
    123$#@ER    Frank
    

    You can test online at regex101, where you can find also an analytical explanation. To be honest though, my approach is a little bit complicated for a person who doesn't know a lot about regular expressions. You could use capture groups which will yield the exact same results and will be easier to understand, like this: