Search code examples
regexreplacenotepad++

Notepad++ add new line above changing syntax with replace


I have a constant syntax of "Se " but there is a number in front of it that changes. I want to add a newline \n before the number. I've tried using \c to address any character (for the changing number) during replace, I don't know how to get the number part to copy over or work.

this is what it currently looks like

1            hinge 2pk
1            Se wall cabinet                                                   
4            door 15x40"

I want the new line to be above any item that includes "Se", so that it looks like this

1            hinge 2pk

1            Se wall cabinet                                                   
4            door 15x40"

this is what i've tried so far (not including parenthesis)

REPLACE TOOL

Find what: [\C            Se ]
Replace with: [\n\C            Se ]

✓ = Regular expression

but this is what I get

1            hinge 2pk

C            Se wall cabinet                                                   
4            door 15x40

How do I get the number to the left of "Se" to copy down (as this number is always changing)


Solution

  • You can use:

    ^\d+\h+Se\b
    
    • ^ Start of string
    • \d+ Match 1+ digits
    • \h+ Match 1+ spaces
    • Se\b Match Se followed by a word boundary

    Regex demo

    In the replacement use a newline and the full match \n$0

    Find what:

    ^\d+\h+Se\b
    

    Replace with

    \n$0
    

    enter image description here