Replace every n-line with tabs in the file

Is it possible to replace every 4 lines of break with a tab in UE or NPP using regex search / replace?

File before:

    #12
    ab
    cde
    ef
    #34
    ghij
    ijk
    kl
    #5678
    uv
    w
    xyz
...

      

should be replaced after

#12 ^t ab ^t cde ^t ef
#34 ^t ghij  ^t ijk ^t kl
#5678 ^t uv ^t w  ^t xyz

      

+3


source to share


2 answers


Here's how to do it:

Find what: (.+)\R(.+)\R(.+)\R(.+\R)?


Replace with:$1\t$2\t$3\t$4

Check Regular Expression


Do NOT check dot matches newline


and click Replace All

.



Explanation:

(.+)\R   : Capture in group 1 everything until a line break (excluded)
(.+)\R   : Capture in group 2 everything until a line break (excluded)
(.+)\R   : Capture in group 3 everything until a line break (excluded)
(.+\R)?  : Capture in group 4 everything until a line break (included), optional

      

\R

denotes any type of string (i.e. \R

either \n

or \r\n

)

+4


source


[\n\r](?!#)

Will do and replace with \t

It will replace crlf if no # by tab follows after using windowed encoding. (?!#)

- negative result, which excludes any \ n or \ r followed by # (on the next line)



Beware of leaving a space in front of the tabs, if you really only want the tab between each field, you may need to change the encoding to only have \ n or \ r (linux or mac).

+1


source







All Articles